Skip to content

Files and attachments

import { blob } from "platform:blob";

Two concepts: a blob is stored bytes, an attachment links a blob to a record. Uploading and attaching are separate steps, so one file can hang off several records without being stored twice.

const record = await blob.upload({
filename: "report.csv",
mimeType: "text/csv",
data: new TextEncoder().encode(csv),
});

data is a Uint8Array. Returns a BlobRecord whose id you attach with.

await blob.attach(issue.record_id, record.blob_id, {
fieldKey: "evidence",
displayOrder: 0,
});
ArgumentPurpose
recordIdRecord to attach to
blobIdBlob to attach
fieldKeyGroups attachments under a named field
displayOrderSort order, defaults to 0
const attachments = await blob.listAttachments(issue.record_id);
const { data, filename, mimeType } = await blob.getData(blobId);
const text = new TextDecoder().decode(data);
await blob.removeAttachment(attachmentId); // unlink, keep the blob
await blob.delete(blobId); // delete the bytes

Removing an attachment leaves the blob, which matters when it is attached elsewhere. Deleting the blob affects every record referencing it.

Uploads are capped server-side, 100 MB by default. Exceeding it fails the call.