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).uploadFile
Uploads a file (PDF, JPEG, PNG or WebP) without server-side processing. The file type is inferred from the MIME type.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.MIME type used when wrapping a
Uint8Array. Defaults to
"application/octet-stream". Ignored when file is already a Blob.Custom key-value data stored on the file. The server adds
originalFilename alongside, replacing any
value of yours under that key.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.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. TheimageOptions 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).
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.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.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.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, itsimage data (variants, processing details) is included. A file the viewer can’t see answers 404, like a missing one.
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.
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.
refreshFileLinks
Fresh links for files whose links expired. Every file link stops working at its File’slinksExpireAt, 24 to 48 hours after it was read; store file ids, and
ask for fresh links when you need them.
The user this read acts as. Without it, only files that belong to nothing, and those anyone can see, come back.
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).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.Promise<void>
