Working with BLOBs

Properties of the datatype BLOB are used to store binary data, like a file upload.

Uploading BLOB data to an existing item

You can upload binary large objects (BLOBs) to any existing item with a BLOB type field using the POST method.

It is essential that the item exists prior to uploading. The URL should specify the item identifier and the field designated to store the BLOB.

Use Content-Type multipart/form-data when uploading files. The field name must be file.

Uploading to a specific item field

Sample URL format for uploading BLOB data against restapi.com:

https://<region>.restapi.com/<api-name>/<collection-name>/<item-id>/<blob-field-name>

Sample URL format for uploading BLOB data against restapi.cloud:

https://<api-name>.restapi.cloud/api/<collection-name>/<item-id>/<blob-field-name>

Replace <blob-field-name> with the name of the BLOB field where the file should be stored.

If the upload is successful, a 200 OK response is returned.

In case of failure, such as the item does not exist or the field name does not support BLOBs, a 400 bad request or 404 not found response is returned.

Sample request to upload a file

Example using CURL to upload a file:

curl -X POST -F "file=@path_to_file" https://<target>/<collection-name>/<item-id>/<blob-field-name>

Example using fetch with form to upload a file:

fetch("https://<target>/<collection-name>/<item-id>/<blob-field-name>", {
  method: "POST",
  body: new FormData(document.getElementById('upload-form'))
});

Example using fetch without form to upload a file:

const file = e.target.files[0];
const formData = new FormData();
formData.append("file", file);
fetch("https://<target>/<collection-name>/<item-id>/<blob-field-name>", {
    method: "POST",
    body: formData
});

Example using axios to upload a file:

const formData = new FormData();
formData.append("file", blob, "confirmation.pdf");
_axios.post("https://<target>/<collection-name>/<item-id>/<blob-field-name>", formData, {
    headers: {
        "Content-Type": "multipart/form-data",
    },
});

Ensure that the item identifier and BLOB field name are correctly specified in the URL. The path_to_file should be the local path to the file you wish to upload.