Ruza Drive / Guides
Uploads and content hash
Upload a file to Ruza Drive through the API: in one request up to 100 MiB, or as a resumable upload in 4 MiB blocks, with the content hash algorithm and its test vectors.
Which upload to choose
| Upload | Size | Requests | Resume after a cut |
|---|---|---|---|
Single request, POST /files | 100 MiB at most | One | No: start again |
Resumable, POST /uploads | Any size | Two, plus one per 4 MiB block | Yes, block by block |
Both give the same result, a file or a new version of a file, and use the same quota. The single request suits small files; the resumable upload serves large files and fragile connections.
Single-request upload
POST /files?parent_id=…&name=… with the file's bytes in the body and the Content-Length header. The server cuts the body into 4 MiB blocks, computes the hashes as it reads and returns the entry and its version (201).
if_exists:fail(default, 409name_conflict),new_version(one more version of the file of that name) orrename("report (2).pdf").modified_at: the modification date to keep (RFC 3339); otherwise, the time of the upload.- New version of a known file:
PUT /files/{id}/content. WithIf-Match(the current version ID, the ETag of a download), the request fails with 412 if another version arrived meanwhile.
Resumable upload
- Open the session:
POST /uploadswithparent_id,nameandsize. The answer givesid,block_size(4,194,304 bytes) andchunk_count. - Send the blocks:
PUT /uploads/{id}/chunks/{index}, indices from 0, the last block shorter, each with itsContent-Digest. Any order, several blocks may go in parallel, and sending an identical block again is harmless. - Resume after a cut:
GET /uploads/{id}returns the blocks received as inclusive ranges ([[0,41],[43,43]]); send only the missing ones. Every block received extends the session's expiry. - Complete:
POST /uploads/{id}/completewithcontent_hash, the content hash of the whole file (below). The answer is the entry and its version. - Give up:
DELETE /uploads/{id}frees the space the blocks reserved.
Open
Send a block
Complete
base_version_id, given when opening, protects a new version: completion fails with 412 if the file got another current version meanwhile.
Content-Digest of a block
Every block carries the Content-Digest header (RFC 9530): the block's SHA-256 in base64, between sha-256=: and :. A block that does not match is refused (422 digest_mismatch); send it again.
The content hash
The content hash is the SHA-256 of the concatenated SHA-256 digests of the 4 MiB blocks, in order, written in lower-case hexadecimal. The last block may be shorter. An empty file has no block: its hash is the SHA-256 of nothing.
So it is not the SHA-256 of the whole file: even a one-block file has the SHA-256 of its SHA-256 as its hash. It is the content_hash of versions (GET /files/{id}/versions) and of the change feed, handy to recognise content already there.
Test vectors
Check your implementation with these vectors, produced by the server's reference implementation and used by the tests of the Ruza Drive Windows client. The file of each vector holds size bytes, byte i being (i × 7 + 13) mod 251; 4,194,304 bytes make one block.
Common errors
| Code | HTTP | Meaning |
|---|---|---|
| too_large | 413 | The body is too large: 100 MiB at most for a single-request upload, 1 MiB for JSON. Beyond, use a resumable upload. |
| length_required | 411 | The Content-Length header is missing: a single-request upload must give it. |
| digest_mismatch | 422 | The block received does not match its Content-Digest. Send it again. |
| content_hash_mismatch | 422 | The hash given does not match the blocks received. See the uploads guide. |
| upload_incomplete | 409 | Blocks are missing: GET /uploads/{id} gives those received. |
| upload_closed | 410 | The upload session is completed, cancelled or expired. Open another one. |
| name_conflict | 409 | An entry with this name already exists in the folder; details.existing_id gives its ID. |
| quota_exceeded | 507 | Not enough storage left. Free some space or change plan. |