Skip to main content

Overview

Uploading files to the drive uses a three-step multipart upload flow via S3. This approach supports large files reliably by splitting them into parts that are uploaded directly to S3 using signed URLs.

Upload Flow

Step 1: Start the Upload

POST /public/v1/drive/files/upload/multipart/start Initiate a new multipart upload by providing file metadata. Request body:
  • fileName (required): Name of the file being uploaded.
  • fileSize (required): Total file size in bytes.
  • mimeType (required): MIME type of the file (e.g., application/pdf, image/png).
  • parentId (optional): ID of the parent folder. Omit to upload to the root.
Response:
  • uploadId: The S3 multipart upload identifier.
  • fileKey: The S3 object key for this file.

Step 2: Get Presigned URLs

POST /public/v1/drive/files/upload/multipart/presigned-urls Request signed URLs for each part of the file. Request body:
  • uploadId (required): The upload ID from Step 1.
  • fileKey (required): The file key from Step 1.
  • parts (required): The number of parts to upload. Split your file into chunks and request one URL per chunk.
Response:
  • urls: Array of signed URLs, one for each part. Each URL is used to upload a single chunk via HTTP PUT.

Step 3: Upload Parts to S3

Upload each file chunk directly to S3 using the signed URLs from Step 2. For each part:
  1. Send an HTTP PUT request to the signed URL with the file chunk as the body.
  2. Record the ETag header from each S3 response — you will need it in the next step.

Step 4: Finalize the Upload

POST /public/v1/drive/files/upload/multipart/finalize Complete the upload by providing the part information from S3. Request body:
  • uploadId (required): The upload ID from Step 1.
  • fileKey (required): The file key from Step 1.
  • parts (required): Array of objects, each containing:
    • partNumber: The 1-based index of the part.
    • eTag: The ETag value returned by S3 when uploading that part.
Response:
  • Returns the created drive item with its ID, name, and metadata.

Example

# Step 1: Start upload
curl -X POST https://api.copera.ai/public/v1/drive/files/upload/multipart/start \
  -H "Authorization: Bearer YOUR_PAT" \
  -H "Content-Type: application/json" \
  -d '{"fileName": "report.pdf", "fileSize": 10485760, "mimeType": "application/pdf"}'

# Step 2: Get presigned URLs (e.g., 2 parts for a 10MB file)
curl -X POST https://api.copera.ai/public/v1/drive/files/upload/multipart/presigned-urls \
  -H "Authorization: Bearer YOUR_PAT" \
  -H "Content-Type: application/json" \
  -d '{"uploadId": "abc123", "fileKey": "files/xyz", "parts": 2}'

# Step 3: Upload each part to S3 (using URLs from Step 2)
curl -X PUT "SIGNED_URL_1" --data-binary @part1.bin
curl -X PUT "SIGNED_URL_2" --data-binary @part2.bin

# Step 4: Finalize
curl -X POST https://api.copera.ai/public/v1/drive/files/upload/multipart/finalize \
  -H "Authorization: Bearer YOUR_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "uploadId": "abc123",
    "fileKey": "files/xyz",
    "parts": [
      {"partNumber": 1, "eTag": "\"etag-from-s3-1\""},
      {"partNumber": 2, "eTag": "\"etag-from-s3-2\""}
    ]
  }'