Overview
Uploads an image to Sublay storage. The server processes the image, generates named variants according to the specified mode, and returns the File with signed links to the original and every variant. The links expire at the File’slinksExpireAt (File links), so store the file’s id, not a link. The options are sent as one JSON field, file.options: the same options a record’s own images take (for example avatarFile on useUser).
Works in both browser and React Native environments. Provides upload progress tracking.
The uploaded file isn’t attached to anything. A file that belongs to a record is sent with that record’s own hook (for example, the images of useCreateEntity).
Requires an authenticated user. The hook uses the private axios instance and will throw if no session is active.
Usage Example
Parameters
uploadImage({ file, ...options }) takes one object: the file, plus the processing configuration (UploadImageOptions) and the call’s own onProgress and metadata.
The image to upload. In the browser, pass a standard
File object. In React Native, pass { uri, name, type? }. Not part of file.options.The processing mode. See Processing Modes below. Every requested size is 1–10000 px, and
dimensions, widths, heights and sizes take at most 30 entries (one variant each). Unknown keys in the options, a key of another mode included, are refused with 400 storage/invalid-body. A variant name uses only letters, digits, _, - and ., is at most 64 characters, can’t contain .., and can’t be original.Common Options (all modes)
Output format for all variants. Defaults to
"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.How each variant fits its requested size. Defaults to
"inside". The values each mode takes are listed under Processing Modes.The longest side, in px, the stored original is shrunk to (50–10000). Defaults to
3840. An original already within it keeps its dimensions. originalSize, originalWidth and originalHeight describe the stored original. A larger original takes more storage, which counts toward the project’s file-storage limit.Folder segments for the stored image. The new file’s id is always added after them (
<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.Called with upload percentage (0–100) during the multipart upload. Not sent to the server.
Custom key-value data stored on the file, sent as its own field (not inside
file.options). 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.Processing Modes
exact-dimensions
Each variant has an explicit pixel width and height.
aspect-ratio-width-based
All variants share a fixed aspect ratio. You specify widths; heights are computed.
aspect-ratio-height-based
All variants share a fixed aspect ratio. You specify heights; widths are computed.
original-aspect
Preserves the original image’s aspect ratio. You specify the longest-edge size for each variant.
multi-aspect-ratio
Picks the ratio in aspectRatios closest to the image and generates one variant per sizes entry.
Returns
Async function that performs the upload and resolves with the File on success.
Return Value Shape (File)
The File, the same shape Fetch File returns, its image data included:

