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.
blob.upload
Section titled “blob.upload”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.
blob.attach
Section titled “blob.attach”await blob.attach(issue.record_id, record.blob_id, { fieldKey: "evidence", displayOrder: 0,});| Argument | Purpose |
|---|---|
recordId | Record to attach to |
blobId | Blob to attach |
fieldKey | Groups attachments under a named field |
displayOrder | Sort order, defaults to 0 |
blob.listAttachments
Section titled “blob.listAttachments”const attachments = await blob.listAttachments(issue.record_id);blob.getData
Section titled “blob.getData”const { data, filename, mimeType } = await blob.getData(blobId);const text = new TextDecoder().decode(data);Removing
Section titled “Removing”await blob.removeAttachment(attachmentId); // unlink, keep the blobawait blob.delete(blobId); // delete the bytesRemoving an attachment leaves the blob, which matters when it is attached elsewhere. Deleting the blob affects every record referencing it.
Size limits
Section titled “Size limits”Uploads are capped server-side, 100 MB by default. Exceeding it fails the call.