File upload
A drop zone to pick files: drag, click, keyboard or paste. Checks type, size and count as files arrive, lists them as ray-attachment rows (thumbnails, remove) and submits them with its form.
In a raylang app
In a std/ui window with the native bridge, native makes browsing open the system's file dialog, with the accept types as its filter. The files it gives are paths on the user's disk, not bytes: they list like any other file (name, size, type) and the program reads them.
<form id="import">
<ray-file-upload name="photos" native multiple accept="image/*" label="Photos"></ray-file-upload>
</form>
upload.addEventListener("change", () => {
window.ray.send("import:" + JSON.stringify(upload.paths)); // ["/Users/ada/Pictures/a.jpg", …]
});
The form submits those paths under name. Dropped and pasted files are still File objects (upload.files holds both; a chosen one is a HostFile with a path). Without the bridge, or in a browser, native changes nothing.
API
For AI agents: this API as Markdown, or every component in llms-full.txt.
<ray-file-upload> · RayFileUpload
A drag that can only be refused turns the zone red before the drop; refused files fire ray-reject and are explained under the zone. Without multiple a new file replaces the current one. Uploading is the app's: attachmentFor(file) gives the row whose progress/status/error to set.
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
name | name reflects | string | Form field name: every file is submitted under it. | |
label | label | string | Label above the zone. | |
description | description | string | Help text under the label. | |
error | error | string | Error text (replaces the explanation of refused files). | |
required | required reflects | boolean | The form needs at least one file. | |
disabled | disabled reflects | boolean | No picking, dropping or removing. | |
accept | accept reflects | string | Accepted types, as in <input type=file>: ".pdf,.png", "image/*", "application/json". | |
multiple | multiple reflects | boolean | Several files (else one, replaced by the next). | |
maxSize | max-size | string | Largest file: bytes or a size like "10 MB", "512 KB". | |
maxFiles | max-files | number | With multiple: the most files kept. | |
hint | hint | string | Small text in the zone. Default: from accept, max-size and max-files ("PNG or PDF · up to 10 MB each · max. 5 files"). | |
dropLabel | drop-label | string | Drag files here (text file-upload.drop) | Title of the zone, before "or browse". |
browseLabel | browse-label | string | browse (text file-upload.browse) | The link-styled word (the button text in compact). |
activeLabel | active-label | string | Drop to add files (text file-upload.active) | Title while files are dragged over it. |
tapLabel | tap-label | string | Choose files (text file-upload.tap) | Title on touch screens (no hover), where dragging files is rare. |
variant | variant reflects | default | compact | default | default: a tall centered zone; compact: one row with a Browse button. |
list | list reflects | rows | cards | none | rows | How chosen files show: full-width rows, thumbnail cards, or not at all (render your own on change). |
native | native reflects | boolean | With a native host (ray-elements/core/raylang.js in a std/ui window), browsing opens the system dialog and gives paths (see `paths`); drop and paste still give Files. | |
color | color reflects | string | Accent of hover, drag and the browse link (default: primary). |
| Event | Description |
|---|---|
change | Files were added or removed (read `files`, and `lastChange` for which). |
ray-reject | Some files were refused (type, size or count). |
ray-error | The native dialog failed (with `native`). |
| Slot | Description |
|---|---|
icon | Replaces the upload icon. |
| Part | Description |
|---|---|
dropzone | The zone (a button). |
icon | The icon tile. |
hint | The small text in the zone. |
files | The list of chosen files. |
label | The label. |
error | The error text. |
Texts
What it writes itself, in English; setStrings() translates them (Getting started: Languages).
| Key | English |
|---|---|
file-upload.drop | Drag files here |
file-upload.browse | browse |
file-upload.active | Drop to add files |
file-upload.tap | Choose files |
file-upload.images | Images |
file-upload.videos | Videos |
file-upload.audio | Audio |
file-upload.text | Text files |
file-upload.types | {list} or {last} |
file-upload.too-large | {name} is larger than {size}. |
file-upload.only-one | Only one file can be added. |
file-upload.max | { one: "Up to {count} file can be added.", other: "Up to {count} files can be added." } |
file-upload.full | No more files can be added |
file-upload.room | { one: "Only {count} more file", other: "Only {count} more files" } |
file-upload.refused | File type not allowed |
file-upload.required | Select at least one file. |
file-upload.hint-size | up to {size} |
file-upload.hint-size-each | up to {size} each |
file-upload.hint-max | { one: "max. {count} file", other: "max. {count} files" } |