Uploads API
To upload files, use a workspace API key with permission read_write, a signed-in user with an editor or admin role, or a read_write sandbox token. A key with permission search can read upload and operation status. Save the upload, drive and workspace IDs so you can check progress later.
The Python SDK and the CLI handle hashing, transfers, bulk requests and polling for you. See authentication for request headers, and errors and recovery for failed requests.
File formats
You can upload any type of file. Choose its format:
format | Use for | What happens |
|---|---|---|
pdf, docx, txt, md | PDF, Word, plain text and Markdown files | Stored, and their text is read so you can read it by line or byte with the text route. The bytes must match the format. A PDF or DOCX without a text layer is kept, with text_status: none. TXT and Markdown must be UTF-8 (a byte-order mark is fine). |
file | Anything else: photos, video, audio, archives, models, code, data | Stored as it is and found by path, name and metadata. Its bytes can be read, streamed, written in place and, for UTF-8 text, edited. The service adds media.* facts it reads from media files, such as media.kind. |
Empty (0-byte) files are stored like any other; their sha256 is the digest of no bytes. See limits for sizes.
Upload one file
- Prepare the upload with the file's name, format, size, SHA-256 digest and
external_id. - Transfer the bytes the way the transfer response says.
- Complete the upload. The file is saved and processing starts.
- Follow the upload and its operation until processing finishes.
On macOS or Linux, compute the size and digest and prepare the upload:
printf '%s\n' 'Refunds are available within 30 days of purchase.' > handbook.txt
FILE_SIZE=$(wc -c < handbook.txt | tr -d ' ')
FILE_SHA256=$(shasum -a 256 handbook.txt | cut -d ' ' -f 1)
curl -X POST "https://api.flashdrive.space/v1/drives/$DRIVE_ID/uploads" \
-H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
-H "Flashdrive-Client: my-app/1.0.0" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: handbook-prepare-1" \
-d "{\"external_id\":\"handbook.txt\",\"filename\":\"handbook.txt\",\"format\":\"txt\",\"size_bytes\":$FILE_SIZE,\"sha256\":\"$FILE_SHA256\"}"
Set UPLOAD_ID to the response's id, then ask where to send the bytes:
curl -X POST "https://api.flashdrive.space/v1/drives/$DRIVE_ID/uploads/$UPLOAD_ID/transfer" \
-H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
-H "Flashdrive-Client: my-app/1.0.0" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: handbook-transfer-1" \
-d '{}'
Follow the transfer instructions
The transfer response chooses how to send the bytes:
| Response | Next step |
|---|---|
{"transport":"proxy"} | PUT the original bytes to the upload's /content route, with your credential, Content-Type: application/octet-stream and an idempotency key. Then complete with {}. |
{"transport":"direct","url":"…","headers":{…},"expires_in":600} | PUT the original bytes to the returned url with exactly the returned headers and the file's Content-Length. The URL itself authorizes this transfer; do not send your credential to it. Then complete with {"transport":"direct"}. expires_in is at most 600 seconds; if it passes, ask for new transfer instructions. |
A large file is sent in parts instead.
A proxy transfer followed by completion:
curl -X PUT "https://api.flashdrive.space/v1/drives/$DRIVE_ID/uploads/$UPLOAD_ID/content" \
-H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
-H "Flashdrive-Client: my-app/1.0.0" \
-H "Content-Type: application/octet-stream" \
-H "Idempotency-Key: handbook-content-1" \
--data-binary @handbook.txt
curl -X POST "https://api.flashdrive.space/v1/drives/$DRIVE_ID/uploads/$UPLOAD_ID/complete" \
-H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
-H "Flashdrive-Client: my-app/1.0.0" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: handbook-complete-1" \
-d '{}'
The declared size and SHA-256 must describe these exact bytes; otherwise the transfer returns 400 checksum_mismatch. Keep the same body and key when you retry a step.
Follow processing
After completion, read the upload until it has an operation_id or reports a failure, then follow the operation:
curl "https://api.flashdrive.space/v1/workspaces/$WORKSPACE_ID/operations/$OPERATION_ID" \
-H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
-H "Flashdrive-Client: my-app/1.0.0"
queued and running mean work continues; searchable means processing finished; failed means read error_code and error_message. Wait between checks and stop at a time limit you choose. Processing continues after your client disconnects. Keep the upload and operation IDs for recovery.
Replace a specific revision
To replace an uploaded file, including after merging a conflict copy, prepare a single upload for the new bytes and add three fields from the file you read with GET /v1/drives/{drive_id}/documents/{document_id}:
{
"document_id": "DOCUMENT_UUID",
"external_id": "handbook.txt",
"expected_revision": "3"
}
document_id and expected_revision go together, and external_id must be the file's own. The revision is the file's latest_revision: a positive decimal string. The service checks it when the upload is prepared and again when it is accepted; if the file changed meanwhile, the upload fails with 412 stale_version and nothing is overwritten. Read the file again before you decide what to do. An external_id that is not the file's own also returns stale_version, and document_id without expected_revision returns 428 precondition_required.
Include every metadata label and the folder you want to keep: a replacement does not merge the old labels. Bulk reservations do not take these fields; replace files one at a time. Do not replace an uploaded file with PUT .../documents/{document_id}, which is for text records.
Upload routes
POST /v1/drives/{drive_id}/uploads
Prepare an upload and reserve storage for the file. Requires Idempotency-Key.
| Field | Type | Presence | Guidance |
|---|---|---|---|
external_id | string | Required | Your stable key for the file within the drive, at most 1,024 UTF-8 bytes. It must be new to the drive: one the drive already has returns 428 precondition_required. To replace that file, send document_id and expected_revision as well. |
filename | string | Required | 1 to 255 UTF-8 bytes. Path separators (/, \), line breaks and other control characters return 400 invalid_filename. |
format | pdf, docx, txt, md, file | Required | See file formats. |
size_bytes | integer | Required | 0 to 10,000,000,000. |
sha256 | string | Required | SHA-256 of the original bytes: 64 lowercase hexadecimal characters. |
folder_id | string or null | Optional | The destination folder. |
metadata | object | Optional | Labels. See metadata limits. |
document_id | string | Optional | With expected_revision, replace exactly this revision. |
expected_revision | string | Optional | The file's current latest_revision. |
201: id, state and expires_in (86,400: send and complete the file within 24 hours). After that, transfer and completion return 409 upload_expired or upload_sealed; prepare a new upload. A drive with too many transfers in progress returns 429 upload_limit with Retry-After.
POST /v1/drives/{drive_id}/uploads/{upload_id}/transfer
Get or renew the transfer destination. Requires Idempotency-Key; send {}. 200: one of the objects in transfer instructions.
POST /v1/drives/{drive_id}/uploads/{upload_id}/multipart
Send a large file in parts. Requires Idempotency-Key. Body: action, one of begin, parts, complete or verify, and for parts a parts array of 1 to 16 entries, each with part_number and md5 (the part's MD5, base64).
200: transport (multipart), state (uploading, verifying or verified), part_size, part_count, verified_bytes and completed (the parts stored so far). After parts, the answer also has parts: for each part asked for, its part_number, size_bytes, url, headers and expires_in.
beginreturns the part size and count, and which parts are already stored.partsreturns a link for each part you name.PUTthe part's bytes to itsurlwith exactly itsheaders. The link itself authorizes the part; do not send your credential to it.completewhen every part is stored, thenverifyuntilstateisverified.- Finish with complete, sending
{"transport":"direct"}.
expires_in is how many seconds a part's link stays valid: at most 3,600, and never longer than the upload itself has left. An older drive issues links of at most 600 seconds. When a link has run out, ask for the part again with parts; the parts already stored are kept.
PUT /v1/drives/{drive_id}/uploads/{upload_id}/content
Send the original bytes through the API (the proxy transport). Requires Idempotency-Key. 200: id, state and uploaded: true.
POST /v1/drives/{drive_id}/uploads/{upload_id}/complete
Verify the bytes, save the file and start processing. Requires Idempotency-Key. Body: {"transport":"direct"} after a direct transfer, or {} after a proxy transfer. 202: id, state, and when known document_id, operation_id, committed_revision, warnings, error_code and error_message. Completing an upload whose bytes never arrived returns 409 upload_incomplete. The preconditions are checked again here: a replacement whose file changed since it was prepared returns 412 stale_version, and a new file whose external_id was taken meanwhile returns 409 already_exists. Repeating completion with the same key recovers a lost answer.
GET /v1/drives/{drive_id}/uploads/{upload_id}
Read an upload.
| Field | Type | Meaning |
|---|---|---|
id | string | Upload UUID. |
state | string | For example awaiting_content, queued, running, accepted or failed. |
document_id | string or null | The file, once known. |
operation_id | string or null | The processing operation, once known. |
committed_revision | string or null | The file revision this upload made, once known. |
warnings | array | Each has a code; PDF page warnings also have a page number, from 1. |
error_code, error_message | string or null | Why the upload failed. |
timings | object | See below. |
timings has created_at, uploaded_at (bytes verified and saved), searchable_at (processing finished), and the durations in milliseconds transfer_ms, queue_ms, processing_ms, uploaded_to_searchable_ms and total_ms. A value is null until it is known, or when a step was skipped; null does not mean zero.
GET /v1/workspaces/{workspace_id}/operations/{operation_id}
Read an operation. Optional query drive_id limits the lookup to one drive.
| Field | Type | Meaning |
|---|---|---|
id | string | Operation UUID. |
status | queued, running, searchable, failed | searchable means processing finished. |
error_code, error_message | string or null | Why the operation failed. |
created_at | string | When it started. |
completed_at | string or null | When it finished. |
document_count | integer | Files in the operation. |
progress | object | For progressive text records: accepted_documents, indexed_documents (processed) and failed_documents. |
Bulk uploads
Bulk routes reserve, complete and check many files in one request each. Every file has its own result, so keep the files that succeeded and follow up on the ones that need attention. The SDK and the CLI use these routes for you. Not every drive has them: read the drive's capabilities first.
GET /v1/drives/{drive_id}/uploads/capabilities
Read how the drive takes uploads. Read it before you upload more than one file.
| Answer | Meaning |
|---|---|
{"version":1,"max_items":50,"max_body_bytes":65536} | The drive has the bulk routes. max_items is the most files one bulk request names and max_body_bytes the largest JSON body of one. Keep every bulk request within them. |
{"version":2,"max_items":1,"max_body_bytes":65536} | The drive takes files one at a time and has no bulk routes; they return 409 not_supported_on_this_drive. Upload each file on its own. max_body_bytes is the largest JSON body an upload route accepts. |
Treat a version you do not know as version 2: upload files one at a time. GET /v1/sdk/context also returns conservative bulk defaults in upload_batch; the drive's own answer decides.
POST /v1/drives/{drive_id}/uploads/batch
Reserve uploads. Requires Idempotency-Key. Send a files array; each entry has the single-upload fields except document_id and expected_revision, plus key: 1 to 128 characters, unique in the request and stable when you retry that file.
{
"files": [
{
"key": "library-0001",
"external_id": "opening-hours.txt",
"filename": "opening-hours.txt",
"format": "txt",
"size_bytes": 18,
"sha256": "REPLACE_WITH_SHA256_OF_THE_FILE"
}
]
}
201: files in request order. An accepted entry has its key, upload id, state and, when bytes are still needed, a transfer object (transport, and for direct the url, headers and expires_in). An entry that needs attention has key and error_code, and retry_after_seconds when it can be retried later with the same key and inputs.
POST /v1/drives/{drive_id}/uploads/batch/complete
After sending the bytes, complete the uploads. Requires Idempotency-Key.
{"files":[{"id":"UPLOAD_UUID","transport":"direct"}]}
transport is direct or proxy, as used for that file. 202: files, each with its state and any error_code. Repeat with the same IDs to recover an interrupted answer.
POST /v1/drives/{drive_id}/uploads/batch/status
Read many uploads at once. Requires Idempotency-Key. Body: {"ids": ["UPLOAD_UUID", "..."]}, unique IDs from this drive. 200: files in the requested order, each with id, state, document_id, operation_id, warnings, error_code, processing_status (queued, running, searchable or failed) and processing_error_code.
Upload capacity
Each drive has its own capacity, shared by every client uploading to it:
- A limited number of active transfers (prepared, unfinished and unexpired single uploads).
- A limited number of outstanding uploads, counting active transfers and files waiting for or in processing.
Past either, preparing an upload returns 429 upload_limit with Retry-After. A transfer slot frees up once the file is completed. Files already completed stay queued for processing and do not expire.
GET /v1/drives/{drive_id}/ingestion-metrics
Read the drive's capacity and processing queue. 200: scope (drive), drive_id, active_transfers, transfer_limit (50), outstanding_limit (10,000) and processing, with:
| Field | Meaning |
|---|---|
queued, running | Work waiting and in progress. |
failed | Uploads and operations that are still failed. Uploading the file again does not clear an earlier failure. |
pending_bytes | Original bytes still waiting for or in processing, as a decimal string. |
oldest_queued_ms | Age of the oldest queued item, or null. |
Bulk imports
Bulk imports load a large collection of TXT and Markdown files into one drive. They are available to organizations that have them enabled; for others, the import routes return 404 not_found or 503 temporarily_unavailable.
An import groups files into chunks. You declare the totals, upload each chunk to its own URL, acknowledge it, then seal the import. Files are processed while later chunks are still uploading. Choose a new UUID for each import and keep it: the import ID makes creation safe to retry, so these routes do not use Idempotency-Key.
While an import batch is being applied to a drive, other writes to that drive return 503 temporarily_unavailable. Retry them later; other drives are not affected. Imports count toward drive limits and your storage.
| Limit | Value |
|---|---|
| Source bytes per import | 100,000,000,000 |
| Files per import | 100,000 |
| Chunks per import | 100,000 |
| Bytes per chunk | 32,000,000 |
| Files per chunk | 10,000 |
| Chunks declared per request | 32 |
| Chunks declared but not acknowledged | 32, and at most 1,000,000,000 bytes |
| Formats | txt and md, UTF-8, not empty |
Chunk format
A chunk is a 4-byte big-endian manifest length, a JSON manifest, then the file bodies one after another. The manifest lists each file:
{"schema":"flashdrive-import-chunk.v1","mode":"create","documents":[
{"external_id":"guides/setup.md","filename":"setup.md","format":"md","metadata":{},
"expected_revision":null,"offset":0,"size_bytes":1834,"sha256":"<hex>"}]}
schema is always the value shown. offset and size_bytes locate each file in the bodies, and sha256 is the file's digest. In create mode, expected_revision is null and the external IDs are new. In replace mode, give each file's current revision; otherwise the import reports import_revision_conflict. The chunk's own sha256 and encoded_bytes cover the whole chunk, and source_bytes is the sum of its file sizes.
PUT /v1/drives/{drive_id}/imports/{import_id}
Create the import with {"source_bytes": <total>, "documents": <total>}. One import takes at most 100,000 files (the documents total you declare) and 100,000,000,000 source bytes; larger totals return 400 invalid_upload_batch, so split the collection into several imports. 201: the import. Repeating the same request returns the same import; other totals return 409 idempotency_conflict. Totals past the drive limits return 409 drive_limit_exceeded.
The import has id, state (open, sealed or closed), expires_at (Unix milliseconds), the declared source_bytes and documents, the counters declared_*, acknowledged_*, searchable_* (processed) and failed_* for bytes and documents, released (unused reserved storage was returned) and complete (sealed, and everything acknowledged is processed).
POST /v1/drives/{drive_id}/imports/{import_id}/chunks
Declare 1 to 32 chunks: {"chunks":[{"sequence":0,"sha256":"<hex>","encoded_bytes":4096,"source_bytes":4000,"documents":12}]}. Number chunks from 0 without gaps. Each returned chunk has a transfer object: PUT the chunk bytes to its url with exactly its headers within expires_in seconds. Declaring the same chunk again returns a fresh destination. 409 request_in_progress means too many chunks are waiting for acknowledgement or too much declared content is waiting for processing: acknowledge chunks or wait, then retry. Declaring past the import's totals, or the same sequence with other values, returns 409 idempotency_conflict.
POST /v1/drives/{drive_id}/imports/{import_id}/chunks/{sequence}/acknowledge
Send {} after the chunk upload succeeds. The service checks the stored chunk against its declaration and returns a receipt; repeating returns the same receipt. 404 not_found means the chunk is not stored yet. 400 invalid_upload_batch means the chunk does not match its declaration, or holds an unsupported format, invalid UTF-8 or an empty file.
POST /v1/drives/{drive_id}/imports/{import_id}/seal
Send the final totals: {"chunks": <count>, "source_bytes": <total>, "documents": <total>}. They must match the declared chunks, and every chunk must be acknowledged; otherwise 409 idempotency_conflict. Sealing ends the uploads; processing continues.
GET /v1/drives/{drive_id}/imports/{import_id}
Read progress and a page of chunks: after (default -1) and limit (1 to 1,000, default 100). Each chunk lists its state, attempts, last_error and any failed_operations.
Other import actions
POST .../closewith{}stops the import early and releases unused storage.POST .../recoverwith{}restores access to an existing import, for example after a lost reply to creation.POST .../operations/{operation_id}/retrywith{"request_id": "<uuid>"}retries a failed operation listed infailed_operations. Reuse the samerequest_idwhen you retry the request.
An open import that passes its expires_at closes. While imports are paused for maintenance, creating one returns 503 temporarily_unavailable and declaring or acknowledging chunks returns 409 upload_expired: read the import, and if its state is still open, retry later.