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’slinksExpireAt (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:
The file to upload. In the browser, pass a standard
File object. In React Native, pass { uri, name, type? }.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.Custom key-value data stored on the file. The server adds
originalFilename alongside, replacing any value of yours under that key.Called with upload percentage (0–100) during the multipart upload. Not sent to the server.
Returns
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.The
type field is inferred automatically from the file’s MIME type: a PDF becomes "document" and an image becomes "image".
