Skip to content

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

UploadSizeRequestsResume after a cut
Single request, POST /files100 MiB at mostOneNo: start again
Resumable, POST /uploadsAny sizeTwo, plus one per 4 MiB blockYes, 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, 409 name_conflict), new_version (one more version of the file of that name) or rename ("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. With If-Match (the current version ID, the ETag of a download), the request fails with 412 if another version arrived meanwhile.

Resumable upload

  1. Open the session: POST /uploads with parent_id, name and size. The answer gives id, block_size (4,194,304 bytes) and chunk_count.
  2. Send the blocks: PUT /uploads/{id}/chunks/{index}, indices from 0, the last block shorter, each with its Content-Digest. Any order, several blocks may go in parallel, and sending an identical block again is harmless.
  3. 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.
  4. Complete: POST /uploads/{id}/complete with content_hash, the content hash of the whole file (below). The answer is the entry and its version.
  5. Give up: DELETE /uploads/{id} frees the space the blocks reserved.

Open

post/uploads
curl -X POST "https://api.ruzagency.com/drive/v1/uploads" \
  -H "Authorization: Bearer rza_YOUR_KEY" \
  -H "Idempotency-Key: 3c1f6a2e-8b4d-4e7a-9f0c-1d2e3f4a5b6c" \
  -H "Content-Type: application/json" \
  -d '{
    "parent_id": "root",
    "name": "backup-2026-11-23.tar",
    "size": 734003200
  }'
{
  "upload": {
    "id": "0c9d8e7f-1a2b-4c3d-8e4f-5a6b7c8d9e0f",
    "parent_id": "b7d24c19-3a5e-4f60-8b21-9c0d1e2f3a4b",
    "name": "Invoice-2026-03.pdf",
    "size": 184320,
    "mtime": "2026-03-02T09:14:00Z",
    "block_size": 4194304,
    "chunk_count": 175,
    "state": "open",
    "expires_at": "2026-12-31T23:59:59Z",
    "received": [
      [
        0,
        41
      ],
      [
        43,
        43
      ]
    ]
  }
}

Send a block

put/uploads/{id}/chunks/{index}
curl -X PUT "https://api.ruzagency.com/drive/v1/uploads/0c9d8e7f-1a2b-4c3d-8e4f-5a6b7c8d9e0f/chunks/0" \
  -H "Authorization: Bearer rza_YOUR_KEY" \
  -H "Content-Digest: sha-256=:X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=:" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @chunk-0.bin
{
  "index": 0,
  "sha256": "1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014",
  "duplicate": false
}

Complete

post/uploads/{id}/complete
curl -X POST "https://api.ruzagency.com/drive/v1/uploads/0c9d8e7f-1a2b-4c3d-8e4f-5a6b7c8d9e0f/complete" \
  -H "Authorization: Bearer rza_YOUR_KEY" \
  -H "Idempotency-Key: 3c1f6a2e-8b4d-4e7a-9f0c-1d2e3f4a5b6c" \
  -H "Content-Type: application/json" \
  -d '{
    "content_hash": "83e7237e08cb83c5b84bb57550753b795abc82c6ba1aee4d54477e3bcd83aeb0"
  }'
{
  "entry": {
    "id": "5f0c8a4e-2d71-4b7e-9a3c-1e2f3a4b5c6d",
    "parent_id": "b7d24c19-3a5e-4f60-8b21-9c0d1e2f3a4b",
    "kind": "file",
    "name": "Invoice-2026-03.pdf",
    "size": 184320,
    "mtime": "2026-03-02T09:14:00Z",
    "revision": 3,
    "current_version_id": "e41a7b2c-6d8e-4f90-a1b2-c3d4e5f6a7b8",
    "created_at": "2026-03-02T09:14:00Z",
    "updated_at": "2026-03-02T09:14:00Z",
    "version_count": 2
  },
  "version": {
    "id": "e41a7b2c-6d8e-4f90-a1b2-c3d4e5f6a7b8",
    "seq": 2,
    "size": 184320,
    "mtime": "2026-03-02T09:14:00Z",
    "origin": "upload",
    "created_at": "2026-03-02T09:14:00Z",
    "content_hash": "83e7237e08cb83c5b84bb57550753b795abc82c6ba1aee4d54477e3bcd83aeb0",
    "current": true
  }
}

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.

echo "sha-256=:$(openssl dgst -sha256 -binary block-000000 | base64):"

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.

blocks = the file cut into blocks of 4,194,304 bytes (the last one shorter)
hash   = hex( SHA-256( SHA-256(block 0) || SHA-256(block 1) || ... ) )
empty  = SHA-256("") = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

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.

#!/usr/bin/env bash
# Usage: ./content-hash.sh backup.tar (needs coreutils and xxd)
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
split -b 4194304 -a 6 -d "$1" "$tmp/block-"
shopt -s nullglob
for block in "$tmp"/block-*; do
  sha256sum "$block" | cut -c1-64 | xxd -r -p
done | sha256sum | cut -c1-64

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.

# size (bytes)  content hash
0        e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  # empty file
1        e17d630e7b1ec8612c95f2a37755c70466640272a6aee967e16239f2c66a81d4
1024     404a55bde7489220f7c1ebeb684b91b97df8869f693b1759114160dc7db11ca3
4194303  3561bdd681e54e1a70a0c762e8b54545e605160562f7c1c900d079940e48f3c8  # 4 MiB - 1
4194304  83e7237e08cb83c5b84bb57550753b795abc82c6ba1aee4d54477e3bcd83aeb0  # 4 MiB, one block
4194305  0ddc628d19c4330221626f206026d528a0a2d8b2c41bdf4ebe6505d2929c3b1b  # 4 MiB + 1, two blocks
8400953  e412a662caaa15dff8d142b37e3ccee243387e6f839de7351333fffb0f4cbacb  # 2 × 4 MiB + 12,345, three blocks
const bytes = Buffer.alloc(size);
for (let i = 0; i < size; i++) bytes[i] = (i * 7 + 13) % 251;

Common errors

CodeHTTPMeaning
too_large413The body is too large: 100 MiB at most for a single-request upload, 1 MiB for JSON. Beyond, use a resumable upload.
length_required411The Content-Length header is missing: a single-request upload must give it.
digest_mismatch422The block received does not match its Content-Digest. Send it again.
content_hash_mismatch422The hash given does not match the blocks received. See the uploads guide.
upload_incomplete409Blocks are missing: GET /uploads/{id} gives those received.
upload_closed410The upload session is completed, cancelled or expired. Open another one.
name_conflict409An entry with this name already exists in the folder; details.existing_id gives its ID.
quota_exceeded507Not enough storage left. Free some space or change plan.
Next guideChange feed