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 a browser File (e.g. from an <input type="file">)
or a Blob. There is no Uint8Array + mimeType path; the browser supplies
the content type.
A file uploaded with this module isn’t attached to anything: it has no entity, comment, space or event. A file that belongs to a record is sent with that record’s own call
(for example, the coverFile, images and files of sublay.events.createEvent).
Uploads are attributed to the logged-in user automatically (from the token) —
there is no
userId param. A user may delete files they own. Reads
(getFile, refreshFileLinks) return only files the user can see: a file that
belongs to a record goes to whoever can see that record
(who can see a file).uploadFile
Uploads a file (PDF, JPEG, PNG or WebP) without server-side processing.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", "reports"] →
documents/reports/<fileId>/<filename>. Each part is slugified. Defaults to
["files"]. A folder that is, or becomes, . or .. is refused with
400 storage/invalid-body.Custom key-value data stored on the file. The server adds
originalFilename alongside, replacing any
value of yours under that key.Promise<File>: the File, keyed id.
The file is stored as uploaded, so image is null, even for an image.
uploadImage
Uploads an image, processes it server-side, and stores the original plus all requested variants. TheimageOptions object is a discriminated union on mode —
the other fields depend 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).
The image to upload, as a browser
File or Blob. Must be a format the server
can process.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.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 user can’t see answers 404, like a
missing one.
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.
Promise<{ files: File[] }>: a fresh File
for each id the user can see, in the order asked for. A file that’s missing, or
that the user 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).Promise<void>
The call only succeeds when the logged-in user owns the file; otherwise it
returns
403.
