Skip to main content

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 URL#

First, you need to get a pre-signed URL for uploading the file.

API Endpoint#

GET https://api.documentpro.ai/v1/documents/upload_url

Query Parameters#

  • file_name (required): The name of the file you want to upload.

Headers#

  • x-api-key (required): Your API key for authentication.

Example Using cURL#

curl --location 'https://api.documentpro.ai/v1/documents/upload_url?file_name=large_document.pdf' \--header 'x-api-key: YOUR_API_KEY'

Example Using Python#

import 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 URL#

Use the upload_url from Step 1 to upload your file directly to our storage.

Example Using cURL#

curl --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 Upload#

After successful upload, confirm it with DocumentPro.

API Endpoint#

POST https://api.documentpro.ai/v1/documents

Headers#

  • x-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 cURL#

curl --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 Python#

import 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)

Response#

The response will be the same as for regular file uploads, containing the document details.

Important Notes#

  1. The pre-signed URL from Step 1 is temporary and will expire after a short period.
  2. Ensure you complete all steps in order and handle any errors that may occur during the process.
  3. The Content-Type header in Step 2 should match the actual file type you're uploading.
  4. For browser uploads, ensure CORS is properly configured on your end.

Next Steps#

After successfully uploading a large document:

  1. Run a parser on the uploaded document using its document_id.
  2. Retrieve parsing results once the parsing is complete.
  3. List your documents to see all uploaded documents in your account.