Besides JSON documents, the document server can store blobs. Blobs are immutable byte sequences. A blob's token is its SHA 256 hash, written as 64 hex digits.
Blobs are linked from documents using #b
:
Blobs not linked from any document are removed by the garbage collector.
Note that blobs are plain byte sequences. To store metadata, create a document with the metadata, and link the blob from there.
To store blobs, the account must have the blobs
flag set to true
:
Using Backend.js, blobs can be uploaded as follows:
const backend = new Backend('https://viereck.ch/backend'); const account = backend.account('your-account-id', '44705748... your-account-key'); const data = ...; // string, blob, arraybuffer, or Uint8Array account.writeBlob(data, onDone, onError); function onDone(token, request) { ... } function onError(errorCode, request) { ... }
and downloaded as follows
backend.readBlob(token, onDone, onError); function onDone(bytes, request) { ... } function onError(errorCode, request) { ... }
HEAD /backend/blobs/TOKEN
204
if the blob exists
404
if the blob does not exist
Checks if a blob exists on the store without retrieving it.
GET /backend/blobs/TOKEN
200
with the blob content
404
if the blob does not exist
Retrives the blob with the given token.
GET /backend/blobs/TOKEN/FILENAME
200
with the blob content
404
if the blob does not exist
Retrives the blob with download headers. Browsers typically save the blob to a download folder rather than displaying it.
200
with the blob token
Stores a blob. The content may be any sequence of bytes.
The blob token is the SHA256 sum of its bytes, written as 64 hex digits. This value is also used as part of the signature.
If UDP is enabled, the following requests are available.
Requests a blob. If the blob does not exist, the server responds with N
. Otherwise, slices of the blob are transmitted. Dropped packets can be requested again by sending a request with the missing ranges.
Writes a blob, and responds with the blob token.
Note that the maximum blob size is limited by the maximum UDP packet size of about 65000 bytes (using packet fragmentation). Larger blobs must be written via HTTP.