File Upload

PRO

Configure file selection, drag and drop, file lists, and upload status.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-file-upload
  label="Attachments"
  accept=".pdf,.png,.txt"
  max-size="5242880"
  max-files="3"
  multiple
  button-label="Choose files"
  drag-label="Drop files here"
  id="sample"
></sy-file-upload>
<div class="demo-actions"
  style="display:flex;flex-wrap:wrap;gap:8px;margin-top:16px"
>
  <sy-button id="action-0" size="small">View list</sy-button>
  <sy-button id="action-1" size="small">Clear all</sy-button>
</div>
<output id="demo-result" aria-live="polite"></output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  const actionTarget0 = document.querySelector("#sample");
  document.querySelector('#action-0').addEventListener('click', async () => {
    const result = await actionTarget0.getFiles();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget1 = document.querySelector("#sample");
  document.querySelector('#action-1').addEventListener('click', async () => {
    const result = await actionTarget1.clear();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
</script>

Usage guide

#

Show file selection and upload progress. Connect actual server uploads in your app.

  1. 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.

  2. 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.

  3. 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.

  1. Define selection constraints

    accept sets file types, maxSize sets the size in bytes, and maxFiles sets the maximum count.

  2. Connect uploads

    Read selected files from selected or changed and send them to the server.

  3. Update progress

    Update progress with setProgress(), and manage the list with removeFile() or clear().

Feature examples

#

Choose a feature from 30 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.

Usage examples · Overview

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Property · Accept

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Button Label

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Disabled

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Drag Label

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Helper Text

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Hide Files

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Label

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Max Files

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Max Size

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Message

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Multiple

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · No Native Validity

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Required

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Slot Error

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Slot Message

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · State

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · checkValidity

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · clear

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · getFile

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · getFiles

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · open

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · removeFile

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · reportValidity

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · setCustomError

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · setProgress

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Events · Changed

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Removed

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · Selected

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Slot ·

Compare the content placed inside the component with its slot names in the code.

View code
HTML
Loading the example.

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 / PropertyTypeDefaultDescription
booleanfalseBlock user interaction and keyboard focus.
booleanfalseFail form validation when no value is provided.
string''Accepted file extensions or MIME types.
booleanfalseAllow multiple file selection.
number0Maximum size of one file in bytes. Set to 0 for no limit.
number0Maximum 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.
booleanfalseHide the list of selected files.
string''Label describing the item.
string''Help text about the input state.
booleanfalseUse 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

EventDetailDescription
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

MethodReturnsDescription
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

SlotDescription
Component body or child items.
Validation error message.
Input help message.