Skip to main content

Overview

Uploads a file to Sublay storage without any server-side processing. The raw file is stored and a proxy URL is returned. Use this for PDFs, videos, Office documents, or any file type where you don’t need variant generation. For images that need resizing or format conversion, use useUploadImage instead.
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, options?) accepts three arguments:
BrowserFile | RNFile
required
The file to upload. In the browser, pass a standard File object. In React Native, pass { uri, name, type? }.
string[]
required
Storage path segments. The file is stored under the joined path, with a UUID sub-folder appended automatically for uniqueness. For example, ["documents", "user-123"] stores the file at documents/user-123/<uuid>/<filename>. A folder that is, or contains, . or .. is refused with a 400.
UploadFileOptions
Optional associations and metadata.

Options

string
Associates the file with an entity. The file is deleted when the entity is deleted. Only the entity’s author can attach to it.
string
Associates the file with a comment. The file is deleted when the comment is deleted. Only the comment’s author can attach to it.
string
Associates the file with a space.
number
Display order when a record has multiple attachments, from 0 to 10000. Defaults to 0.
Record<string, any>
Custom key-value data stored alongside the file record.
Naming a record in 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.

Returns

The hook returns the uploadFile function directly (no state wrappers). The function returns a Promise<UploadResponse>:
The type field is inferred automatically from the file’s MIME type. PDFs and Office documents become "document", video files become "video", images become "image", and everything else becomes "other".