File Upload
PROConfigure file selection, drag and drop, file lists, and upload status.
Usage guide
#Show file selection and upload progress. Connect actual server uploads in your app.
Write the error message in the error slot.
Inside the component, add <span slot="error">Error message</span>. You can include links and other guidance as well as text. For inputs supporting noNativeValidity, enable it to show this guidance instead of a browser popup. Switch always displays errors below the component.
Report business rule failures with setCustomError().
For example, if the server rejects a duplicate value, update the error slot and call setCustomError(). This method does not take a message argument. A custom error also blocks form submission.
Clear the error after resolving it and check whether submission is allowed.
Use clearCustomError() to clear a business rule error. Required-field and format validation remain active. await checkValidity() returns true or false; reportValidity() validates and displays errors. Read valid named values through FormData on submission.
Define selection constraints
acceptsets file types,maxSizesets the size in bytes, andmaxFilessets the maximum count.Connect uploads
Read selected files from
selectedorchangedand send them to the server.Update progress
Update progress with
setProgress(), and manage the list withremoveFile()orclear().
Examples
#Feature examples
#Choose a feature from 30 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.
No matching features.
API reference
#Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.
<sy-file-upload>
Properties
| Attribute / Property | Type | Default | Description |
|---|---|---|---|
boolean | false | Block user interaction and keyboard focus. | |
boolean | false | Fail form validation when no value is provided. | |
string | '' | Accepted file extensions or MIME types. | |
boolean | false | Allow multiple file selection. | |
number | 0 | Maximum size of one file in bytes. Set to 0 for no limit. | |
number | 0 | Maximum selectable file count. Set to 0 for no limit. | |
string | 'files' | Field name used in FormData. | |
string | 'Browse files' | File selection button text. | |
string | 'Drop files here or browse' | Instructions in the drop zone. | |
string | '' | Helper text, such as file restrictions. | |
boolean | false | Hide the list of selected files. | |
string | '' | Label describing the item. | |
string | '' | Help text about the input state. | |
boolean | false | Use the app's error UI instead of the browser's built-in error display. checkValidity still performs validation. | |
'' | 'default' | 'error' | 'warning' | 'success' | '' | Status styling for the file upload area. |
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<{ files: SyUploadFileItem[] }> | Fires after the user adds files (drag-drop or browse). Carries the accepted file items. | |
CustomEvent<{ file: File; reason: string }> | Fires for each file rejected by format, size or count limits. | |
CustomEvent<{
files: SyUploadFileItem[];
added: SyUploadFileItem[];
removed: SyUploadFileItem[];
isValid: boolean;
}> | Fires whenever the internal file list changes (selection, removal, status update). `added` / `removed` carry the delta since the previous emit so the consumer can reconcile its own state without diffing the full list. | |
CustomEvent<{ file: SyUploadFileItem; files: SyUploadFileItem[] }> | Fires when a file is removed from the list. | |
CustomEvent<void> | Emitted when focus is received. | |
CustomEvent<void> | Emitted when focus is lost. |
Methods
| Method | Returns | Description |
|---|---|---|
Promise<void> | Open the file chooser. Call within a user click handler. | |
Promise<void> | Clear the selected file list. | |
Promise<void> | Remove the file matching fileId from the list. | |
Promise<void> | Update a file's upload progress and status. | |
Promise<SyUploadFileItem[]> | Return the selected file list. | |
Promise<SyUploadFileItem | null> | Return the file at the specified index. | |
Promise<void> | Mark the specified fileId as the active file. | |
Promise<boolean> | Return true if the current constraints are satisfied, otherwise false. | |
Promise<boolean> | Validate the current value and display errors to the user. | |
Promise<void> | Set a custom error state. | |
Promise<void> | Clear the custom error state. | |
Promise<string> | Return the current validation state. | |
Promise<void> | Move keyboard focus to the input or action element. | |
Promise<void> | Remove focus from the input element. |
Slots
| Slot | Description |
|---|---|
| Component body or child items. | |
| Validation error message. | |
| Input help message. |