Docs

Documentation versions (currently viewingVaadin 24)

Upload

Upload allows the user to upload files, giving feedback to the user during the upload process.

Upload allows the user to upload files, giving feedback to the user during the upload process. It shows the upload progress and the status of each file. Files can be uploaded by clicking on the Upload button, or by dragging them onto the component.

Open in a
new tab
Source code
UploadBasic.java
upload-basic.tsx
upload-basic.ts

Drag & Drop

Upload allows the user to drag files onto the component to upload them. Multiple files can be dropped simultaneously. By default, this is enabled on desktop computers, and disabled on touch devices. Explicitly setting it to enabled or disabled, though, affects both desktop and mobile devices.

Open in a
new tab
Source code
UploadDragAndDrop.java
upload-drag-and-drop.tsx
upload-drag-and-drop.ts

Upload supports uploading folders via drag & drop. This uploads all files from the folder and its sub-folders recursively. The folder structure is flattened and the names of the uploaded files don’t indicate in which folder they were in. Uploading folders is currently not supported through the native file picker.

Auto-Upload

By default, files are uploaded immediately — or at least they’re added to the queue to be uploaded. Auto-upload can be disabled, for example, to allow the user to review the list of files before initiating their upload by clicking the ▶️ button for each file. Change the button label, though, to indicate that uploads don’t start automatically.

Open in a
new tab
Source code
UploadAutoUploadDisabled.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-auto-upload-disabled.tsx
upload-auto-upload-disabled.ts

Uploads can be initiated programmatically when auto-upload is disabled. You might do this, for example, if you want to provide the user with a single button to start all uploads.

Open in a
new tab
Source code
UploadAllFiles.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-all-files.tsx
upload-all-files.ts

Upload Restrictions

You can set three types of restrictions: file format; file count; and file size.

Exceptions that arise — usually from the user violating any of the imposed restrictions — aren’t shown in the UI by default. Use a File Rejected listener to catch those exceptions and, for example, a Notification to inform the user of the problem, together with any potential solutions.

The user should be informed upfront, though, about any file upload restrictions. Limitations on the maximum number of files allowed, file size, and format should all be communicated clearly, to reduce or eliminate exceptions.

File Format

Upload can be configured to accept only files of specific formats. The acceptable file formats are set using MIME type patterns or file extensions (e.g., "video/*", "image/tiff" or ".pdf" and "audio/mp3").

Open in a
new tab
Source code
UploadFileFormat.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-file-format.tsx
upload-file-format.ts
Note
Prefer MIME Type
Although MIME types are widely supported, file extensions are only implemented in certain browsers and should be avoided.
Note
File Format Restrictions are Client-Side

File format restrictions set with setAcceptedFileType method are checked only on the client side. They indicate the hints for users as to what file types to upload.

Using this method won’t restrict the uploaded file’s format on the server side. The Upload component doesn’t have an API to restrict uploaded files by file format or content on the server side. If required, it’s the responsibility of the application developer to implement application-specific restrictions on the server side in one or more of the Upload component’s event listeners (e.g., in Upload::addSucceededListener).

File Count

By default, Upload doesn’t limit the number of files that can be uploaded. However, you can set a file count limit. If you set the maximum to one, the native file browser prevents multiple files from being selected.

Note
Java Flow-Specific
When using a Receiver that doesn’t implement the MultiFileReceiver interface — such as MemoryBuffer or FileBuffer — the Upload component limits the number of files to one. This is because these receiver implementations only support handling a single file at once.
Open in a
new tab
Source code
UploadFileCount.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-file-count.tsx
upload-file-count.ts

File Size

Upload allows you to limit the file size by setting a maximum amount in bytes. By default, though, there is no limit.

Open in a
new tab
Source code
UploadFileSize.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-file-size.tsx
upload-file-size.ts
Note
Revalidate Size Limit on Server
This constraint is set on the client and is checked before contacting the server.

File Actions

Each file has a certain set of associated actions available, depending on its upload state. A file always has a Clear/Remove button. This button cancels the upload if applicable, and removes the file from the list. This button is the only available action during and after a successful upload.

Open in a
new tab
Source code
upload-clear-button.tsx
import React from 'react'; import { useComputed } from '@vaadin/hilla-react-signals'; import { Upload } from '@vaadin/react-components/Upload.js'; import { createFakeUploadFiles } from './upload-demo-helpers'; function createFakeFiles() { return createFakeUploadFiles([ { name: 'Workflow.pdf', progress: 60, status: '19.7 MB: 60% (remaining time: 00:12:34)', }, { name: 'Financials.xlsx', complete: true }, ]); } function Example() { const files = useComputed(createFakeFiles); return <Upload files={files.value} />; }
upload-clear-button.tsx
upload-clear-button.ts
upload-clear-button.ts
Note
Remove the File
The Clear/Remove button doesn’t remove a successfully uploaded file from the server file system or database. It’s only removed from the file list. Remember to remove the file from the backend.

If an error or exception occurs, Upload displays a Retry button for the user to be able to try to upload the file again.

Open in a
new tab
Source code
upload-retry-button.tsx
upload-retry-button.ts
upload-retry-button.ts

When a file is queued (i.e., auto-upload is disabled), there’s a Start Button that the user must press to begin the upload process.

Open in a
new tab
Source code
upload-start-button.tsx
upload-start-button.ts
upload-start-button.ts

Internationalization (i18n)

All labels and messages in Upload are configurable. For a complete list of them, see the API documentation (Java and Web component).

Open in a
new tab
Source code
UploadInternationalization.java
UploadFinnishI18N.java
UploadFinnishI18N.java
upload-internationalization.tsx
upload-internationalization.ts

Customization

You can replace the default upload button. You might do this if Upload needs a stronger emphasis. If so, you can use a primary button.

Open in a
new tab
Source code
UploadButtonThemeVariant.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-button-theme-variant.tsx
upload-button-theme-variant.ts

You can also customize the drop label, as well as the icon.

Open in a
new tab
Source code
UploadDropLabel.java
upload-drop-label.tsx
upload-drop-label.ts
Tip
Large Drop Target
When customizing the Upload component, make sure not to make the drop target too small. A large drop target is easier to use and less error-prone.

Listeners

Upload has listeners for the following events:

All Finished

Triggered when Upload has processed all of the files in its queue, regardless of whether all uploads were successful.

File Rejected

Sent when the file selected for upload doesn’t meet the constraints (e.g., file size limit).

For the following upload events TransferProgressListener should be used, see progress listener

Started

TransferProgressListener::onStart

Finished and Succeeded

TransferProgressListener::onComplete

Progress

TransferProgressListener::onProgress

Failed

TransferProgressListener::onError

Best Practices

With regards to developing with Upload, this section provides some suggestions on how to label buttons and how to construct error messages for better user experiences.

Labeling

Choose labels that are informative and instructive. For example, if the user is to upload a single PDF file, it’s better to have the button label say "Upload PDF…" instead of "Upload File…". The task becomes clearer and improves accessibility for the user — especially if they’re using a screen reader, as the button’s label is read aloud when focused.

Open in a
new tab
Source code
UploadLabelling.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-labelling.tsx
upload-labelling.ts

Likewise, if the user is expected to upload a spreadsheet, but multiple file formats are accepted, label the button, "Upload Spreadsheet". Include helpers to inform the user which formats are accepted.

Open in a
new tab
Source code
UploadHelper.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-helper.tsx
upload-helper.ts

Error Messages

Try to provide meaningful feedback and error messages when an exception or error occurs. Avoid technical jargon. Instead, try to provide solutions and instructions on how to fix the error.

A "Server Unavailable" message might suffice for tech-savvy users, but for some it might be lacking, unhelpful, and frustrating. Error messages should be written with your users in mind.

Open in a
new tab
Source code
UploadErrorMessages.java
UploadExamplesI18N.java
UploadExamplesI18N.java
upload-error-messages.tsx
upload-error-messages.ts

Progress Bar

Component for showing task completion progress.

7426DF11-9CAE-4B52-B1BF-28F3318F58AE