Files

Start an upload for a document

Mints the key the bytes will go to and records it against the document, then answers with the largest body this endpoint takes so a client can refuse an oversized file before it streams anything. The key is the SHA-256 you declare, so starting the same upload twice is the same key twice and the bytes are written once. Send the file to PUT on this same address afterwards. A file larger than one request (a PDF or office document of up to 104857600 bytes, or a clip) opens an upload in parts instead: upload names the part size and count, the parts go to PUT …/content/parts/{part} in order, and POST …/content/complete closes it, with the declared sha256 being the chain of the parts’ hashes. A document that already holds bytes is not replaced here.

The bytes go to the store in the region of the property the document is filed against, read through a lease, a unit or a tenant to the building, and stay there. A document about no property goes to the account’s own region.

post/api/v1/documents/{id}/content

Request

  • Base URL: http://localhost:5180
  • URL: http://localhost:5180/api/v1/documents/{id}/content
  • Auth: API key in cookie better-auth.session_token

Path parameters

idstring required

Document id, for example doc_014.

Request body

contentTypestring required

What the client says the file is. Nothing opens the file to check it, and it is handed back on download exactly as it is given here, which is why it takes no parameters and why a download is always an attachment.

sizeinteger required

How long the file is. The body of the PUT that follows has to be exactly this many bytes or it is refused, and what the account records once they land is R2’s own count of them.

sha256string required

The SHA-256 of the file, lower-case hex. It is the last part of the key the bytes go to, so sending the same file twice writes the same object once, and bytes that hash to anything else are refused.

Response

The upload is open, or the bytes were already there.

okunknown required

Changes

No recorded changes to this operation across all 1 revision of this API.