Products · Upload V1

Document upload

Upload a file from the browser straight to a private AWS S3 bucket.

Version 1 · Files to AWS S3Designed, not builtModule 3 of 15

InterfacesAPI SpecSections

API Spec Designed

Base address: https://01scale.com/api/upload/v1. Open an endpoint for its inputs, constraints, errors and samples.

POST/filesCreate a file and get an upload link

Records a new file and returns a link the browser uses to send the file straight to private storage. The file itself never passes through the API. Signed in

Scope: upload:write

Inputs

file_namebodystringrequired
The name the person sees. Never used as the storage key.
1 to 255 characters after trimming; no /, \ or control characters.
mimebodystringrequired
The file type the browser reports. Checked again against the real bytes on completion.
One of application/pdf, image/png, image/jpeg, application/json, text/csv, and allowed by accept if given.
sizebodyintegerrequired
The exact size in bytes. The upload link only accepts this size.
1 to 10,485,760 (10 MB), and at most accept.max_bytes if given.
acceptbodyobjectoptional
The calling app's own limits. DocFlow sends PDF, PNG and JPEG, 10 MB and 10 pages.
{mimes[], max_bytes, max_pages}; each value may only narrow the service's limits, never widen them. max_pages 1 to 10, PDFs only.
Idempotency-Keyheaderstringoptional
Makes a retried request safe.
1 to 255 characters. Same key and same body within 24 hours returns the first response.

What it does

  • Checks the inputs against the service's limits and accept, before anything is stored.
  • Creates the file with status pending_upload and storage key users/{owner_id}/{file_id}/original.{ext}, where ext comes from mime.
  • Signs an S3 PUT link valid for 5 minutes. Content-Type and Content-Length are part of the signature, so S3 refuses a different type or size.
  • Records file.created in the audit log.

Responses

  • 201The file was created. file (status pending_upload) and upload: url, method (always PUT), the headers the browser must send, and expires_at.
  • 413file_too_large size is over 10 MB or over accept.max_bytes.
  • 415unsupported_file_type mime is not one of the allowed types, or not allowed by accept.
  • 422validation_failed Another input is missing or malformed; errors[] lists each field.
  • 422idempotency_key_reused The same Idempotency-Key was sent with a different body.
  • 401not_authenticated No valid access token.
  • 503storage_unavailable AWS S3 could not be reached. Nothing was changed; safe to retry.

Sample request

POST /api/upload/v1/files HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>
Idempotency-Key: 8b1f6c2e-upload-1
Content-Type: application/json

{
  "file_name": "acme-invoice-0042.pdf",
  "mime": "application/pdf",
  "size": 248913,
  "accept": {
    "mimes": [
      "application/pdf",
      "image/png",
      "image/jpeg"
    ],
    "max_bytes": 10485760,
    "max_pages": 10
  }
}

Sample response

{
  "file": {
    "id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "file_name": "acme-invoice-0042.pdf",
    "mime": "application/pdf",
    "size_bytes": 248913,
    "pages": null,
    "status": "pending_upload",
    "rejection_reason": null,
    "sha256": null,
    "created_at": "2026-11-17T09:14:07Z",
    "completed_at": null,
    "expires_at": "2026-12-17T09:14:07Z"
  },
  "upload": {
    "url": "https://01scale-uploads.s3.us-east-1.amazonaws.com/users/0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e/0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b/original.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAEXAMPLE%2F20261117%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20261117T091407Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-length%3Bcontent-type%3Bhost&X-Amz-Signature=5f2c...",
    "method": "PUT",
    "headers": {
      "Content-Type": "application/pdf",
      "Content-Length": "248913"
    },
    "expires_at": "2026-11-17T09:19:07Z"
  }
}
POST/files/{fileId}/completeConfirm the upload and check the file

Called after the browser has sent the file. Upload checks what actually arrived in storage and marks the file ready or rejected. Safe to call more than once. Signed in

Scope: upload:write

Inputs

fileIdpathuuidrequired
The file to confirm.
A file of the caller's.

What it does

  • If the file is already ready or rejected, returns it unchanged.
  • Asks S3 whether the object exists and compares its size with the size declared at creation.
  • Reads the first bytes to confirm the real type: %PDF- for PDF, the PNG signature, FF D8 FF for JPEG; JSON must parse, CSV must be valid UTF-8 text.
  • For a PDF, counts its pages with a PDF parser (not by text search) and checks them against accept.max_pages. An image counts as 1 page.
  • Passing: computes the SHA-256 of the content, sets status ready, pages and completed_at, and records file.uploaded.
  • Failing a check: sets status rejected with a rejection_reason, deletes the object from S3, and records file.rejected. This is still a 200: the check ran and has an answer.

Responses

  • 200The check has run. file with status ready, or rejected and its rejection_reason: type_mismatch, too_many_pages, unreadable.
  • 401not_authenticated No valid access token. The gateway normally answers this before the request arrives.
  • 404file_not_found No such file, or it belongs to another user. The same answer in both cases.
  • 409upload_missing Nothing has arrived in storage yet, for example the browser has not finished sending. Safe to retry.
  • 409size_mismatch What arrived is not the declared size. The object is deleted; create a new file to try again.
  • 409file_deleted The file was deleted or has expired.
  • 503storage_unavailable AWS S3 could not be reached. Nothing was changed; safe to retry.

Sample request

POST /api/upload/v1/files/0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b/complete HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "file": {
    "id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "file_name": "acme-invoice-0042.pdf",
    "mime": "application/pdf",
    "size_bytes": 248913,
    "pages": 2,
    "status": "ready",
    "rejection_reason": null,
    "sha256": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b",
    "created_at": "2026-11-17T09:14:07Z",
    "completed_at": "2026-11-17T09:14:11Z",
    "expires_at": "2026-12-17T09:14:07Z"
  }
}
GET/files/{fileId}Get one file

A file's details and status. Signed in

Scope: upload:read

Inputs

fileIdpathuuidrequired
The file.
A UUID.

What it does

  • Read only.

Responses

  • 200The file exists and is the caller's. file.
  • 401not_authenticated No valid access token. The gateway normally answers this before the request arrives.
  • 404file_not_found No such file, or it belongs to another user. The same answer in both cases.

Sample request

GET /api/upload/v1/files/0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "file": {
    "id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
    "file_name": "acme-invoice-0042.pdf",
    "mime": "application/pdf",
    "size_bytes": 248913,
    "pages": 2,
    "status": "ready",
    "rejection_reason": null,
    "sha256": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b",
    "created_at": "2026-11-17T09:14:07Z",
    "completed_at": "2026-11-17T09:14:11Z",
    "expires_at": "2026-12-17T09:14:07Z"
  }
}
GET/filesList my files

The caller's files, newest first. Signed in

Scope: upload:read

Inputs

statusquerystringoptional
Only files with this status.
One of pending_upload, ready, rejected. Deleted and expired files are never listed.
cursorquerystringoptional
Where to continue.
A next_cursor from an earlier page, unchanged.
limitqueryintegeroptional
How many to return.
1 to 100. Default 20.

What it does

  • Read only. Ordered by created_at then id, newest first.

Responses

  • 200Always, even when empty. data[] of files and next_cursor (null on the last page).
  • 422validation_failed status, cursor or limit is not valid.
  • 401not_authenticated No valid access token.

Sample request

GET /api/upload/v1/files?status=ready&limit=2 HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "data": [
    {
      "id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
      "file_name": "acme-invoice-0042.pdf",
      "mime": "application/pdf",
      "size_bytes": 248913,
      "pages": 2,
      "status": "ready",
      "rejection_reason": null,
      "sha256": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b",
      "created_at": "2026-11-17T09:14:07Z",
      "completed_at": "2026-11-17T09:14:11Z",
      "expires_at": "2026-12-17T09:14:07Z"
    }
  ],
  "next_cursor": null
}
GET/files/{fileId}/download-urlGet a link to read the file

A link valid for 5 minutes that opens or downloads the file directly from storage. Signed in

Scope: upload:read

Inputs

fileIdpathuuidrequired
The file.
A file of the caller's with status ready.
dispositionquerystringoptional
Show in the browser, or download.
inline (default) or attachment.
filenamequerystringoptional
The name the downloaded file gets.
1 to 255 characters; same rules as file_name. Default: the file's file_name.

What it does

  • Signs an S3 GET link valid for 5 minutes, with the content type and Content-Disposition fixed in the signature.
  • Records file.downloaded when disposition is attachment.

Responses

  • 200The file is ready. url and expires_at.
  • 401not_authenticated No valid access token. The gateway normally answers this before the request arrives.
  • 404file_not_found No such file, or it belongs to another user. The same answer in both cases.
  • 409file_not_ready The file is still uploading, or was rejected.
  • 410file_expired The file was removed after 30 days.
  • 503storage_unavailable AWS S3 could not be reached. Nothing was changed; safe to retry.

Sample request

GET /api/upload/v1/files/0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b/download-url?disposition=attachment HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

{
  "url": "https://01scale-uploads.s3.us-east-1.amazonaws.com/users/0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e/0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b/original.pdf?response-content-disposition=attachment%3B%20filename%3D%22acme-invoice-0042.pdf%22&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAEXAMPLE%2F20261117%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20261117T091407Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=5f2c...",
  "expires_at": "2026-11-17T09:25:00Z"
}
DELETE/files/{fileId}Delete a file

Removes the stored object and marks the file deleted. Safe to call more than once. Signed in

Scope: upload:write

Inputs

fileIdpathuuidrequired
The file.
A file of the caller's.

What it does

  • Deletes the object from S3, sets status deleted and deleted_at, and records file.deleted.
  • A file that is already deleted returns 204 again.

Responses

  • 204The file is deleted. No body.
  • 401not_authenticated No valid access token. The gateway normally answers this before the request arrives.
  • 404file_not_found No such file, or it belongs to another user. The same answer in both cases.
  • 503storage_unavailable AWS S3 could not be reached. Nothing was changed; safe to retry.

Sample request

DELETE /api/upload/v1/files/0193b0c9-5f22-7a08-9e44-1a2b3c4d5e6f HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>

Sample response

HTTP/1.1 204 No Content
POST/eventsReceive platform events

Where other services' signed events arrive. In version 1 Upload acts on one: a user's account was deleted, so their files go too. Service

Scope: None: HMAC signature

Inputs

X-01scale-Signatureheaderstringrequired
Proves the event came from the platform.
HMAC-SHA256 of the raw body with the shared events key, compared in constant time.
event_idbodyuuidrequired
The event's ID.
Each event is processed once; a repeat returns 200 with no effect.
typebodystringrequired
What happened.
Version 1 acts on identity.user.deleted; other types are acknowledged and ignored.
databodyobjectrequired
The event's details.
For identity.user.deleted: {user_id}.

What it does

  • For identity.user.deleted: deletes the object of each of that user's files, using the keys in upload.files (so the service never needs permission to list the bucket), marks the files deleted, and records file.deleted for each with reason: account_deleted.

Responses

  • 200Accepted, including a repeat or an ignored type. No body.
  • 401invalid_signature The signature is missing or wrong.

Sample request

POST /api/upload/v1/events HTTP/1.1
X-01scale-Signature: sha256=8c1f...
Content-Type: application/json

{
  "event_id": "0193b2aa-6f01-7c2d-9e3f-4a5b6c7d8e9f",
  "type": "identity.user.deleted",
  "occurred_at": "2026-11-17T10:00:00Z",
  "data": {
    "user_id": "0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e"
  }
}

Sample response

HTTP/1.1 200 OK

Errors

Every error has the same shape and a stable code to branch on.

{
  "type": "https://01scale.com/errors/file_too_large",
  "title": "File too large",
  "status": 413,
  "detail": "This file is 14.2 MB. The limit is 10 MB.",
  "code": "file_too_large",
  "request_id": "req_0193a61f9c2e"
}

Handled without an endpoint

Sending the file (UPLOAD-V1-E2-02)
The browser PUTs the bytes straight to S3 with the link from POST /files, sending exactly the headers returned. Upload never receives the file's content through its API.
The storage bucket (UPLOAD-V1-E2-01)
Private, encrypted, no public access, objects deleted after 30 days, and CORS open only to 01scale.com and localhost. Setup steps in docs/infra/s3.md.
Abandoned uploads
A daily clean-up deletes files still pending_upload after 24 hours, and their object if one arrived. Files past 30 days are marked expired to match the bucket's own deletion.
DocFlow's endpoints in these stories
POST /api/docflow/v1/documents, …/upload-complete and the documents list belong to the DocFlow app, which calls this service. They are designed with the DocFlow app shell (DOCFLOW-V1-E0-09).
AI agents
Each endpoint above is also a tool on Upload's MCP server, POST /api/upload/mcp, with the same inputs and errors. An agent creates a file and receives the upload link; sending the bytes is an ordinary HTTPS PUT.
Health and contract
Like every service, Upload also serves GET /health and GET /openapi.json from the service template (SERVICEKIT-V1-E0-05).

Constraints at the API level

  • mime must be one of the five allowed types, and allowed by accept if the app sent it.
  • size must be between 1 byte and 10 MB, and within accept.max_bytes.
  • accept can only narrow the service's limits, never widen them.
  • file_name is 1 to 255 characters, with no path separators or control characters; it is never used to build the storage key.
  • The owner is always the token's user; an app storing a file for a user uses a delegated token (decision on #24).
  • Another user's file always answers 404 file_not_found, never 403.
  • Upload and download links last 5 minutes, and fix the type and size (upload) or type and filename (download) in their signature.
  • POST /files accepts Idempotency-Key; complete and DELETE are idempotent by design.
  • Events must carry a valid signature and are processed once per event_id.
  • Rate limits at the gateway (Nikhil's decision on #64): per user, 10 requests a minute that change something (POST, PUT, PATCH, DELETE) and 60 reads a minute; with an API key, 10 requests a minute in total. Over a limit, 429 rate_limited with Retry-After.