Overview
After receiving a pre-signed upload URL from the/upload-url endpoint, you upload your file directly to storage. This direct-to-storage approach ensures fast uploads without bottlenecking through the API server.
Important: Use PUT Method with Raw Bytes
Critical Implementation Details:- Use PUT method (not POST)
- Send raw file bytes as the request body (not multipart/form-data)
- Set the appropriate
Content-Typeheader - Do not include authentication headers (the URL is pre-signed)
Request
Request Details
- Method:
PUT(not POST) - URL: The
upload_urlfrom the/upload-urlresponse - Body: Raw file bytes
- Headers:
Content-Type: The MIME type of your file (e.g.,application/pdf,text/csv,image/png)
Content-Type Headers by File Type
| File Type | Content-Type |
|---|---|
application/pdf | |
| CSV | text/csv |
| Excel | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| JSON | application/json |
| Plain Text | text/plain |
| PNG | image/png |
| JPEG | image/jpeg |
| GIF | image/gif |
| WebP | image/webp |
Response
Success
Status Code:200 OK or 201 Created
The response body is typically empty or contains storage metadata (not needed for your application).
Common Errors
Upload URL Expired
Status Code:403 Forbidden
Invalid Method
Status Code:405 Method Not Allowed
Solution: Use PUT method, not POST.
File Too Large
Status Code:413 Payload Too Large
Solution: Ensure file is under 50 MB limit.
Common Implementation Mistakes
❌ Wrong: Using multipart/form-data
✅ Correct: Using raw bytes
❌ Wrong: Using POST method
✅ Correct: Using PUT method
❌ Wrong: Including authentication
✅ Correct: No authentication (URL is pre-signed)
Complete Example with Error Handling
Next Steps
After successfully uploading your file:- Confirm the upload to trigger automatic file processing → See Confirm Upload
- Use the file_id in chat completions → See Chat Completion API
- Retrieve file metadata to see processing results → See Get Files Metadata
Performance Tips
- File Size: Validate file size before upload to avoid timeouts
- Timeout: Set appropriate timeouts (60+ seconds for large files)
- Retry Logic: Implement retry with exponential backoff for network errors
- Parallel Uploads: For multiple files, upload them in parallel
- Progress Tracking: Use streaming libraries to track upload progress for large files