Skip to main content

Overview

Uploads a file to Sublay storage without any server-side processing. The raw file is stored, and the returned File carries a signed link to it, which expires at the File’s linksExpireAt (File links). Use this for a PDF, or a JPEG, PNG or WebP image you don’t need variants of; other file types are refused with storage/unsupported-file-type. For images that need resizing or format conversion, use useUploadImage instead. 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

uploadFile({ file, pathParts?, metadata?, onProgress? }) takes one object:
BrowserFile | RNFile
required
The file to upload. In the browser, pass a standard File object. In React Native, pass { uri, name, type? }.
string[]
The folder segments the file is stored under, sent as file.options. The new file’s id is always added after them: ["documents", "user-123"] stores the file at documents/user-123/<fileId>/<filename>. Each part is slugified. Defaults to ["files"]. A folder that is, or becomes, . or .. is refused with 400 storage/invalid-body.
Record<string, any>
Custom key-value data stored on the file. The server adds originalFilename alongside, replacing any value of yours under that key.
(progress: number) => void
Called with upload percentage (0–100) during the multipart upload. Not sent to the server.

Returns

(props: UploadFileProps) => Promise<File>
Async function that performs the upload and resolves with the File, keyed id, the same shape Fetch File returns. The file is stored as uploaded, so image is null, even for an image; originalPath is its signed link.
boolean
true while the upload is in progress.
number
Upload percentage (0–100). Resets to 0 when the upload finishes.
The type field is inferred automatically from the file’s MIME type: a PDF becomes "document" and an image becomes "image".