Spaces:
Sleeping
Sleeping
| import requests | |
| import os | |
| # Create a dummy PDF file | |
| with open("test.pdf", "wb") as f: | |
| f.write(b"%PDF-1.4\n1 0 obj\n<<\n/Type /Catalog\n/Pages 2 0 R\n>>\nendobj\n2 0 obj\n<<\n/Type /Pages\n/Kids [3 0 R]\n/Count 1\n>>\nendobj\n3 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/MediaBox [0 0 612 792]\n/Resources <<\n/Font <<\n/F1 4 0 R\n>>\n>>\n/Contents 5 0 R\n>>\nendobj\n4 0 obj\n<<\n/Type /Font\n/Subtype /Type1\n/BaseFont /Helvetica\n>>\nendobj\n5 0 obj\n<<\n/Length 44\n>>\nstream\nBT\n/F1 24 Tf\n100 100 Td\n(Hello World) Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f\n0000000010 00000 n\n0000000060 00000 n\n0000000117 00000 n\n0000000216 00000 n\n0000000303 00000 n\ntrailer\n<<\n/Size 6\n/Root 1 0 R\n>>\nstartxref\n397\n%%EOF") | |
| url = "http://localhost:8000/api/v1/upload/" | |
| files = {'file': ('test.pdf', open('test.pdf', 'rb'), 'application/pdf')} | |
| try: | |
| response = requests.post(url, files=files) | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {response.text}") | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| finally: | |
| if os.path.exists("test.pdf"): | |
| os.remove("test.pdf") | |