Overview
FileUpload is the shared image uploader used in RLink forms. It is a client component that uploads a selected file to /api/upload and returns the uploaded file URL through onChange.
It is designed primarily for image-based CMS and profile-style workflows.
Source
The component is implemented incomponents/ui/FileUpload.tsx.
Props
| Prop | Type | Required | Notes |
|---|---|---|---|
onChange | (url: string) => void | Yes | Receives the uploaded file URL, or "" when cleared |
value | string | null | No | Current uploaded image URL |
accept | string | No | Defaults to image/jpeg,image/png,image/webp,image/gif |
label | string | No | Field label |
hint | string | No | Help text shown when there is no error |
className | string | No | Extra classes |
required | boolean | No | Shows * beside the label |
aspect | "square" | "rectangle" | No | Controls the expected visual crop shape |
What it does
FileUpload handles these responsibilities:
- opens a file picker
- posts the file to
/api/upload - sends cookies with
credentials: "include" - shows uploading and error states
- previews the uploaded image when
valueexists - lets the user clear the current image
Basic usage
Square image example
Upload flow
The component currently:- reads the first selected file
- appends it to
FormData POSTs to/api/upload- parses the JSON response
- calls
onChange(data.url)when successful
Upload failed.
API expectations
ForFileUpload to work correctly, /api/upload should:
- accept multipart form data
- require an authenticated session if uploads are private
- return JSON
- include a
urlfield on success - include an
errorfield on failure when possible
Best practices
- Store the returned URL in form state, not the raw
File - Use
hintto document image requirements for editors - Match
aspectto how the image is displayed in the UI - Keep accepted file types tight for the use case
- Test upload behavior in the real environment, not only on localhost
Edge cases
Authentication
The component sendscredentials: "include", so uploads depend on valid session cookies. If uploads work in one environment and fail in another, check auth and origin settings first.
Only the first file is used
handleFile() reads files?.[0]. Multi-file upload is not supported by this component.
File size limits
The UI hints at a 5 MB max, but the true limit is enforced server-side. Keep client copy and server behavior aligned.Non-image files
By default, the component is configured for images. If you broadenaccept, confirm the backend and preview behavior support those file types too.
Broken preview URL
Ifvalue points to an invalid or expired URL, the preview may fail. The component hides a broken image, but the saved data is still wrong until corrected.
Clearing a value
The clear action callsonChange(""). Make sure the consuming form treats the empty string as “remove image” and not as an accidental no-op.
Related docs
TextInput
Shared text and password field behavior
DropSelect
Consistent dropdown styling and labels
Email and notifications
Helpful when uploaded assets appear in emails or campaigns
Testing
Validate upload success, errors, and auth failures
