Skip to main content
Use the 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:
  • url is 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, a blob: URL included. It stores the string itself as a text file. Upload the File or Blob instead.
  • 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 in filename.
Anything else is dropped without throwing, and the record still saves. That covers data: and blob: URLs, base64, bytes, relative paths, and empty strings.
A write replaces the field’s whole list. To add a file, read the record’s current attachments in the server function and write them back with the new one. To keep the field unchanged, leave it out of the write.
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:
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.

Size limits

The per-file size limit follows the workspace’s plan. Larger files are rejected.