Blobs

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:

{"#b": randomHex(32), "...": null}

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.

Account configuration

To store blobs, the account must have the blobs flag set to true:

{"key": "...", "origins": ["..."], "blobs": true, "...": null}

JavaScript

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) {
	...
}
		

HTTP/REST Requests

Check if a blob exists

Request
HEAD /backend/blobs/TOKEN
Response

204 if the blob exists

404 if the blob does not exist

Checks if a blob exists on the store without retrieving it.

Read a blob

Request
GET /backend/blobs/TOKEN
Response

200 with the blob content

404 if the blob does not exist

Blob token (#b)
Download

Retrives the blob with the given token.

Download a blob

Request
GET /backend/blobs/TOKEN/FILENAME
Response

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.

Write a blob

Request
POST /backend/blobs
Account: ACCOUNT ID
Timestamp: TIMESTAMP
Signature: SIGNATURE
Response

200 with the blob token

Account ID
Account key
Select file to upload

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.

UDP Requests

If UDP is enabled, the following requests are available.

Read a blob

Request

			
Response

			

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.

Write a blob

Request

			
Response

			

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.