storage module uploads files and images to managed cloud storage and returns proxy URLs, plus reads and deletes existing files. Uploads are sent as multipart/form-data — pass the file bytes as a Uint8Array or a Blob.
Uploads can be attributed to a user by passing that user’s Sublay ID as
userId —
your service key performs the upload on behalf of that named user. Omit userId
for a backend/project-owned file (no owning user).uploadFile
Uploads a generic file (PDF, video, document, …) without server-side processing. The file type is inferred from the MIME type.Storage path segments. The file is stored under the joined path with a UUID
sub-folder appended, e.g.
["documents", "usr_abc123"] →
documents/usr_abc123/<uuid>/<filename>. A folder that is, or contains, . or .. is refused with a 400.MIME type used when wrapping a
Uint8Array. Defaults to
"application/octet-stream". Ignored when file is already a Blob.Associates the file with an entity for cascade deletion. Only one of
entityId / commentId / spaceId may be set. Only the entity’s author can attach to it (a service key can attach to any entity).Associates the file with a comment for cascade deletion. Only the comment’s author can attach to it (a service key can attach to any comment).
entityId or commentId needs the right to update it. When the caller may not, the upload is refused with 403 storage/unauthorized (Not authorized to attach a file to this entity., naming the record type). A record that doesn’t exist or counts as missing gets 404 (storage/entity-not-found or storage/comment-not-found): a deleted record, an entity removed by moderation and a comment its author deleted all count as missing. Nothing is stored on either refusal.
Returns — Promise<File>
uploadImage
Uploads an image, processes it with Sharp, 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.
The image bytes. Must be a valid image format recognized by Sharp. Maximum 50 MB.
Image-processing configuration — a discriminated union on
mode. The supported
modes and their required fields:All modes also accept optional
quality (1–100), format (webp | jpeg |
png | original), stripExif (boolean), and fit (cover | contain |
inside | outside). Dimension/size values are 50–10000.Folder segments for the stored image. The new file’s id is always added after them (
<pathParts>/<fileId>/<filename>). 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.Associates the image with an entity. Only one of
entityId / commentId /
spaceId / eventId may be set. Only the entity’s author can attach to it (a service key can attach to any entity).Associates the image with a comment. Only the comment’s author can attach to it (a service key can attach to any comment).
Associates the image with an event. Use this to attach a cover or gallery image
to an event created via
sublay.events.createEvent (the Node SDK does not
support inline event image upload). See the Events module. Only one of the event’s hosts can attach to it (a service key can attach to any event).entityId, commentId or eventId needs the right to update it. When the caller may not, the upload is refused with 403 storage/unauthorized (Not authorized to attach a file to this entity., naming the record type). A record that doesn’t exist or counts as missing gets 404 (storage/entity-not-found, storage/comment-not-found or storage/event-not-found): a deleted record, an entity removed by moderation and a comment its author deleted all count as missing. Nothing is stored on either refusal.
Returns — Promise<File> (the image field carries the generated variants).
getFile
Fetches a file’s metadata and proxy URLs by ID. For images, theimage extension (variants, processing details) is included. Reads are project-scoped.
Promise<File>
deleteFile
Deletes a file record and removes all associated storage objects (for images, every generated variant too).Promise<void>
With a service key this deletes any file in the project. The same call from an
end-user token only succeeds when that user owns the file (otherwise
403).
