Upload
File uploads by drag and drop or from the file picker.
JPEG or PNG up to 5 MB, five photos at most
Your upload function sends each file to the server:
type NuiUploadAdapter<R> = ( file: File, context: { onProgress: (fraction: number) => void; signal: AbortSignal },) => Promise<R>;Report the uploaded share from 0 to 1 to onProgress, and pass signal to fetch so a canceled file stops its request. The returned value becomes the result of the file in the model.
Installation
import { NuiUpload } from '@numior/kit';Usage
Add a few photos, then change the look of the field and the layout of the files.
The first photo goes on the product card
Examples
Show thumbnails
Set layout="grid".
Up to eight photos, the first one becomes the card cover
An image shows as a thumbnail as soon as it is picked, before the upload ends. Files that are already on the server take the thumbnail from their url.
Upload on a button press
Turn off auto and start the upload yourself.
Check the list, then press Upload
Picked files wait in the queued status until you call start() on the component ref.
Keep only a button
Set variant="button".
A CSV table with SKUs and quantities
Such a field takes no dropped files, and the file list stays below the button.
Upload an avatar
Use NuiAvatarUpload.
PNG or JPEG up to 2 MB
Click the avatar or drop an image on it to replace the photo. A file that fails the checks shows the reason and leaves the current photo in place.
Behavior
- Each file goes through the checks: the type against
accept, the size againstmaxSize, the count againstmaxFiles, then yourvalidate. A rejected file stays in the list with the reason, and withrejected="drop"it never gets there. - At most
concurrencyfiles upload at once, and the rest wait in the queue. - Canceling stops the request through
signaland takes the file off the list. A failed upload gets a retry button that sends the same file again. - Removing a file emits
remove, so delete an uploaded file on the server in its handler. With:multiple="false"a new file takes the place of the old one, anddisabledblocks both adding and removing.
Accessibility
A click anywhere in the zone opens the file picker, and on the keyboard the browse button does the same. The label, the hint and the error are linked to that button.
Each row shows the upload progress, and a screen reader announces when a file is uploaded or fails. The cancel, retry and remove buttons have names for screen readers.