Overview
Uploads an image to Sublay storage. The server processes the image using Sharp, generates named variants according to the specified mode, and returns anImage object with proxy URLs for all variants.
Works in both browser and React Native environments. Provides upload progress tracking.
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) accepts two arguments:
The image to upload. In the browser, pass a standard
File object. In React Native, pass { uri, name, type? }.Processing configuration. Must include a
mode field. See Processing Modes below.Common Options (all modes)
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 file with an entity for cascade deletion. Only the entity’s author can attach to it.
Associates the file with a comment for cascade deletion. Only the comment’s author can attach to it.
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.
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
Generates variants across multiple aspect ratios with explicit sizes.
Returns
Async function that performs the upload and returns an
Image object on success.
