useUpload hook from zitejs/upload to upload files from a page: avatars, attachments, images,
documents. It stores the file and returns a permanent URL, which you save in an attachments field or any
other field.
Upload from a page
useUpload() returns an upload function and an isUploading flag:
urlis the file’s permanent, canonical URL. Save it unchanged in database fields.- The filename’s extension sets the stored file type, so include it:
'signature.png', not'signature'. upload()never fetches a URL string, ablob:URL included. It stores the string itself as a text file. Upload theFileorBlobinstead.upload()runs only in the browser. There is no server-side upload. When a server function produces file data, return it to the page and upload it from there.
Save to an attachments field
An attachments field accepts only two kinds of value:- Attachment objects read from a record. Reading an attachments field returns
ZiteAttachment[], each{ filename, originalName, size, mimeType, url, uploadedAt, metadata? }. - Public, direct-download
http(s)URLs, either as a string or as{ url, filename? }. Include the extension infilename.
data: and blob:
URLs, base64, bytes, relative paths, and empty strings.
This page uploads a file, then a mutation’s server function appends it to a ticket’s files field and refreshes every query of the tickets table:
Show file links on the app’s domain
Uploaded files are stored on Zite’s upload hosts. When the app offers a customer-facing file URL (a copy-link button, a download link, an image URL), derive a branded URL on the app’s own domain at render or copy time. Don’t replace the stored canonical URL.- Rewrite only these two exact upload hosts. Leave every other URL unchanged.
- Use the canonical URL during local development.
- Branded URLs stay valid when viewed through the app’s published Zite domain or its custom domain. Keeping the canonical URL in storage means changing a custom domain doesn’t break saved files.
window exists only in the browser, and pages render on the server first. Call the helper in an event
handler, such as a copy button’s
onClick={() => navigator.clipboard.writeText(brandedFileUrl(file.url, window.location.origin))}, or
inside <ClientOnly> from @tanstack/react-router.