Blobs

Drop a file to upload a blob.

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.

HTTP/REST Requests

HEAD /backend/blobs/TOKEN

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

Response

  • 204, if the blob exists
  • 404, if the blob does not exist
GET /backend/blobs/TOKEN

Retrives the blob with the given token.

Response

  • 200 with the blob content
  • 404, if the blob does not exist
GET /backend/blobs/TOKEN/FILENAME

Retrives the blob with download headers. Browsers typically save the blob to a download folder rather than displaying it.

Response

  • 200 with the blob content
  • 404, if the blob does not exist
POST /backend/blobs

Stores a blob. The content may be any sequence of bytes.

The blob token is the SHA256 sum of its bytes. The client submitting the blob may therefore precalculate the blob token before the blob is saved.

Response

  • 200 with the blob token

Metadata

The blob store stores byte sequences only. If you want to store metadata, create a document with the metadata, and link the blob from there.

JavaScript

Using GenericBackend.js, blobs can be uploaded as follows:

const backend = new GenericBackend('https://viereck.ch/backend');

const data = ...;  // string, blob, arraybuffer, or Uint8Array
backend.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) {
	...
}