Upload Large Document
For documents larger than 6MB, DocumentPro uses a multi-step upload process. This guide explains how to upload large files using the API.
#
Step 1: Get Upload URLFirst, you need to get a pre-signed URL for uploading the file.
#
API EndpointGET https://api.documentpro.ai/v1/documents/upload_url
#
Query Parametersfile_name
(required): The name of the file you want to upload.
#
Headersx-api-key
(required): Your API key for authentication.
#
Example Using cURLcurl --location 'https://api.documentpro.ai/v1/documents/upload_url?file_name=large_document.pdf' \--header 'x-api-key: YOUR_API_KEY'
#
Example Using Pythonimport requests
url = "https://api.documentpro.ai/v1/documents/upload_url"params = {"file_name": "large_document.pdf"}headers = {"x-api-key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200: result = response.json() upload_url = result['upload_url'] document_id = result['document_id'] print(f"Upload URL obtained. Document ID: {document_id}")else: print('Failed to get upload URL') print(response.text)
#
Response{ "upload_url": "https://documentpro-user-accounts.s3.amazonaws.com/...", "document_id": "7c5389c6-2ac0-48c5-831a-dd86dae3ec98"}
#
Step 2: Upload File to Pre-signed URLUse the upload_url
from Step 1 to upload your file directly to our storage.
#
Example Using cURLcurl --location --request PUT 'UPLOAD_URL_FROM_STEP_1' \--header 'Content-Type: application/pdf' \--data '@/path/to/your/large_document.pdf'
#
Example Using JavaScript (Browser)const file = document.getElementById('fileInput').files[0];const uploadUrl = 'UPLOAD_URL_FROM_STEP_1';
fetch(uploadUrl, { method: 'PUT', body: file, headers: { 'Content-Type': file.type }, mode: 'cors'}).then(response => { if (response.ok) { console.log('File uploaded successfully'); } else { console.error('Upload failed'); }}).catch(error => console.error('Error:', error));
#
Step 3: Confirm UploadAfter successful upload, confirm it with DocumentPro.
#
API EndpointPOST https://api.documentpro.ai/v1/documents
#
Headersx-api-key
(required): Your API key for authentication.Content-Type
: application/json
#
Body{ "document_id": "DOCUMENT_ID_FROM_STEP_1", "file_name": "large_document.pdf"}
#
Example Using cURLcurl --location 'https://api.documentpro.ai/v1/documents' \--header 'x-api-key: YOUR_API_KEY' \--header 'Content-Type: application/json' \--data '{ "document_id": "7c5389c6-2ac0-48c5-831a-dd86dae3ec98", "file_name": "large_document.pdf"}'
#
Example Using Pythonimport requestsimport json
url = "https://api.documentpro.ai/v1/documents"headers = { 'x-api-key': 'YOUR_API_KEY', 'Content-Type': 'application/json'}payload = json.dumps({ "document_id": "7c5389c6-2ac0-48c5-831a-dd86dae3ec98", "file_name": "large_document.pdf"})
response = requests.post(url, headers=headers, data=payload)
if response.status_code == 200: print('Upload confirmed successfully') print(response.json())else: print('Failed to confirm upload') print(response.text)
#
ResponseThe response will be the same as for regular file uploads, containing the document details.
#
Important Notes- The pre-signed URL from Step 1 is temporary and will expire after a short period.
- Ensure you complete all steps in order and handle any errors that may occur during the process.
- The
Content-Type
header in Step 2 should match the actual file type you're uploading. - For browser uploads, ensure CORS is properly configured on your end.
#
Next StepsAfter successfully uploading a large document:
- Run a parser on the uploaded document using its
document_id
. - Retrieve parsing results once the parsing is complete.
- List your documents to see all uploaded documents in your account.