Skip to main content
The 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 actingUserId, the user your service key acts as. Omit actingUserId for a backend/project-owned file (no owning user).
Access model. Reads (getFile) are project-scoped — reachable for any file in your project. 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 generic file (PDF, video, document, …) 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[]
required
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>.
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.
number
Display order when a record has multiple attachments. Defaults to 0.
object
Custom key-value data stored alongside the file record.
string
Associates the file with an entity for cascade deletion. Only one of entityId / commentId / spaceId may be set.
string
Associates the file with a comment for cascade deletion.
string
Associates the file with a space.
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>

uploadImage

Uploads an image, processes it with Sharp, 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.
Uint8Array | Blob
required
The image bytes. Must be a valid image format recognized by Sharp. 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), format (webp | jpeg | png | original), stripExif (boolean), and fit (cover | contain | inside | outside). Dimension/size values are 50–10000.
string
Name to store the image under. Defaults to "upload".
string
MIME type used when wrapping a Uint8Array. Ignored when file is a Blob.
string[]
Storage path segments. Defaults to ["images", "<fileId>"].
string
Associates the image with an entity. Only one of entityId / commentId / spaceId / eventId may be set.
string
Associates the image with a comment.
string
Associates the image with a space.
string
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.
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 image field carries the generated variants).

getFile

Fetches a file’s metadata and proxy URLs by ID. For images, the image extension (variants, processing details) is included. Reads are project-scoped.
string
required
The UUID of the file to retrieve.
Returns — Promise<File>

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>