# File upload

Source: https://ecosphere.dev/docs/forms/file-upload (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A file picker for one or more files, with the queue of picked files and their upload states.

`import { EcoFileUpload } from "vue-ecosphere"`

## Picker

Choose or drop PDFs. Empty or oversized files are queued as Check file; press Upload with nothing chosen to see the panel error.

Vue (vue-ecosphere):

```vue
<EcoFileUpload v-model="files" label="Supplier contracts" required
  accept=".pdf,application/pdf" :max-size="25 * 1024 * 1024" icon="file-pdf-2-line"
  empty-title="Choose your contracts" empty-hint="Select one or more PDFs from your computer"
  chosen-hint="Add more PDFs or review your selection below"
  choose-label="Choose PDFs" list-label="Selected contracts"
  hint="PDF only · Up to 25 MB per file"
  :error="tried && !files.length ? 'Choose at least one valid PDF to upload.' : undefined" first />
```

React (react-ecosphere):

```tsx
const [files, setFiles] = useState<File[]>([]);

<EcoFileUpload value={files} onChange={setFiles} label="Supplier contracts" required
  accept=".pdf,application/pdf" maxSize={25 * 1024 * 1024} icon="file-pdf-2-line"
  emptyTitle="Choose your contracts" emptyHint="Select one or more PDFs from your computer"
  chosenHint="Add more PDFs or review your selection below"
  chooseLabel="Choose PDFs" listLabel="Selected contracts"
  hint="PDF only · Up to 25 MB per file"
  error={tried && !files.length ? "Choose at least one valid PDF to upload." : undefined} first />
```

## Queue: uploading, saved, failed

Upload sends one file at a time and locks the queue meanwhile. One file fails; Retry remaining files sends only what is not saved.

Vue (vue-ecosphere):

```vue
<EcoFileUpload v-model="files" :status="(f) => statuses.get(f)" … />
<EcoButton variant="primary" size="sm" icon="upload-2-line" :disabled="running" @click="upload">
  {{ running ? "Uploading…" : "Upload" }}
</EcoButton>
```

React (react-ecosphere):

```tsx
<EcoFileUpload value={files} onChange={setFiles} status={(f) => statuses.get(f)} … />
<EcoButton variant="primary" size="sm" icon="upload-2-line" disabled={running} onClick={upload}>
  {running ? "Uploading…" : "Upload"}
</EcoButton>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `File[]` | [] | The queue. Exact duplicates (name, size, last-modified) are dropped. |
| `status` | `(file: File) => EcoFileStatus \| undefined` | — | { state: waiting \| uploading \| saved \| failed \| invalid, progress?, error?, label? } per file. |
| `accept / multiple / maxSize` | `string / boolean / number` | — / true / — | Files that fail these are queued as Check file, never uploaded. |
| `validate` | `(file: File) => string \| undefined` | — | Your own check; return the problem in the reader's terms. |
| `icon` | `string` | "file-line" | File-type tile and row icon, e.g. file-pdf-2-line. |
| `emptyTitle / emptyHint / chosenHint` | `string` | — | Panel copy; it changes with the count. |
| `chooseLabel / addLabel / listLabel` | `string` | "Choose files" / "Add more" / "Selected files" | Button text and the queue's name. |
| `label / required / hint / error / first / disabled` | `—` | — | Field props. The error turns the panel is-invalid. |
| `@files` | `(files: File[]) => void` | — | Files just picked or dropped. |
| `@remove` | `(file: File) => void` | — | A file was removed from the queue. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onChange` | `File[]` | [] | The queue. Exact duplicates (name, size, last-modified) are dropped. |
| `status` | `(file: File) => EcoFileStatus \| undefined` | — | { state: waiting \| uploading \| saved \| failed \| invalid, progress?, error?, label? } per file. |
| `accept / multiple / maxSize` | `string / boolean / number` | — / true / — | Files that fail these are queued as Check file, never uploaded. |
| `validate` | `(file: File) => string \| undefined` | — | Your own check; return the problem in the reader's terms. |
| `icon` | `string` | "file-line" | File-type tile and row icon, e.g. file-pdf-2-line. |
| `emptyTitle / emptyHint / chosenHint` | `string` | — | Panel copy; it changes with the count. |
| `chooseLabel / addLabel / listLabel` | `string` | "Choose files" / "Add more" / "Selected files" | Button text and the queue's name. |
| `label / required / hint / error / first / disabled` | `—` | — | Field props. The error turns the panel is-invalid. |
| `onFiles` | `(files: File[]) => void` | — | Files just picked or dropped. |
| `onRemove` | `(file: File) => void` | — | A file was removed from the queue. |
