Skip to main content
The storage module uploads files and images to managed cloud storage, plus reads and deletes existing files. Both uploads and getFile return the one File shape, with signed links that expire at the File’s linksExpireAt (File links). Uploads are sent as multipart/form-data — pass the file bytes as a Uint8Array or a Blob. A file uploaded with this module isn’t attached to anything: it has no entity, comment, space or event.
Uploads can be attributed to a user by passing that user’s Sublay ID as actingUserId, the user your service key acts as. Omit actingUserId for a backend/project-owned file (no owning user).
Access model. Reads (getFile, refreshFileLinks) return only files the viewer can see: a file that belongs to a record goes to whoever can see that record (who can see a file). Pass actingUserId to read as a user; without it, your service key sees files that belong to nothing and those anyone can see. The owner deletes: a file with an owner is deleted as that user, so pass them as actingUserId. Backend-owned files (uploaded without an actingUserId) are deletable only by your service key naming nobody.

uploadFile

Uploads a file (PDF, JPEG, PNG or WebP) without server-side processing. The file type is inferred from the MIME type.
Uint8Array | Blob
required
The file bytes to upload. Maximum 50 MB.
string[]
The folder segments the file is stored under, sent as file.options. The new file’s id is always added after them, e.g. ["documents", "usr_abc123"] → documents/usr_abc123/<fileId>/<filename>. Each part is slugified. Defaults to ["files"]. A folder that is, or becomes, . or .. is refused with 400 storage/invalid-body.
string
Name to store the file under. Defaults to "upload".
string
MIME type used when wrapping a Uint8Array. Defaults to "application/octet-stream". Ignored when file is already a Blob.
object
Custom key-value data stored on the file. The server adds originalFilename alongside, replacing any value of yours under that key.
string
The user the service key acts as, who owns the upload. Omit it for a backend/project-owned file. A user that doesn’t exist returns 404 storage/user-not-found.
Returns — Promise<File>: the File, keyed id; originalPath is its signed link. The file is stored as uploaded, so image is null, even for an image.

uploadImage

Uploads an image, processes it, and stores the original plus all requested variants. The imageOptions object is a discriminated union on mode — the shape of the other fields depends on the mode you pick. It is sent as one JSON field, file.options, the same options a record’s own images take (avatarFile.options, images.options).
Uint8Array | Blob
required
The image bytes: JPEG, PNG or WebP. Maximum 50 MB.
ImageOptions
required
Image-processing configuration — a discriminated union on mode. The supported modes and their required fields:All modes also accept optional quality (1–100, default 85), format (webp | jpeg | png | original, default webp; original keeps the upload’s format when it is JPEG, PNG or WebP, and stores an image whose content is HEIC or AVIF (sent under a JPEG, PNG or WebP type) as WebP), stripExif (boolean, default true), fit (cover | contain | inside | outside, default inside), originalMaxSize (50–10000, default 3840: the longest side the stored original is shrunk to) and pathParts (the folder: the new file’s id is always added after it, as <pathParts>/<fileId>/<filename>, the file name taking the stored format’s extension; defaults to ["images"]; a folder that is, or contains, . or .. (also written %2e%2e), or that contains ?, # or an encoded slash (%2f, %5c), is refused with a 400). Every requested size is 1–10000 px, and dimensions, widths, heights and sizes take at most 30 entries (one variant each). A variant name uses only letters, digits, _, - and ., is at most 64 characters, can’t contain .., and can’t be original. Unknown keys in the options, a key of another mode included, are refused with 400 storage/invalid-body. See Upload Image for every field.
string
Name to store the image under. Defaults to "upload".
string
MIME type used when wrapping a Uint8Array. Ignored when file is a Blob.
object
Custom key-value data stored on the file. The server adds originalFilename, originalFormat and originalDimensions (the uploaded image’s own name, format and size) alongside, replacing any values of yours under those keys.
string
The user the service key acts as, who owns the upload. Omit it for a backend/project-owned file. A user that doesn’t exist returns 404 storage/user-not-found.
Returns — Promise<File>: the File, keyed id, with its image data (originalWidth, originalHeight, variants, and the processing details). Each variant is { publicPath, width, height, size, format }.

getFile

Fetches a file by ID. For a processed image, its image data (variants, processing details) is included. A file the viewer can’t see answers 404, like a missing one.
string
required
The UUID of the file to retrieve.
string
The user this read acts as: the answer is exactly what that user sees. Without it, only files that belong to nothing, and those anyone can see, come back.
Returns — Promise<File>: the File, the same shape the uploads return. Every owner column (userId, entityId, eventId, commentId, chatMessageId, spaceId) is present, null when unset; image is the image data of a processed image and null otherwise.
Fresh links for files whose links expired. Every file link stops working at its File’s linksExpireAt, 24 to 48 hours after it was read; store file ids, and ask for fresh links when you need them.
string[]
required
Up to 100 file ids.
string
The user this read acts as. Without it, only files that belong to nothing, and those anyone can see, come back.
Returns — Promise<{ files: File[] }>: a fresh File for each id the viewer can see, in the order asked for. A file that’s missing, or that the viewer can’t see, is left out. See Refresh File Links.

deleteFile

Deletes a file record and removes all associated storage objects (for images, every generated variant too).
string
required
The UUID of the file to delete.
string
The user this delete acts as. Required when the file has an owner: pass the owner, and the delete runs exactly as their own (400 storage/missing-user-id without it; anyone else gets 403). Omit it only for a backend-owned file.
Returns — Promise<void>