Skip to content

File Upload

Simple File Upload

html
<six-file-upload id="six-file-upload-success-id"></six-file-upload>
<six-file-list id="six-file-list"> </six-file-list>

<script type="module">
  const fileUpload = document.getElementById('six-file-upload-success-id');
  const fileList = document.getElementById('six-file-list');
  let counter = 0;

  fileUpload.addEventListener('six-file-upload-success', ({ detail }) => {
    const file = detail.file;

    const item = Object.assign(document.createElement('six-file-list-item'), {
      id: String(counter++),
      name: file.name,
      size: file.size,
      date: new Date().toLocaleDateString(),
    });

    item.addEventListener('six-file-list-item-remove', ({ detail }) => {
      const childToRemove = fileList.querySelector(`[name="${detail.name}"]`);
      fileList.removeChild(childToRemove);
    });

    item.addEventListener('six-file-list-item-download', ({ detail }) => {
      alert(`download file ${detail.name}`);
    });

    fileList.append(item);
  });

  const showEvent = ({ type, detail }) => alert(`[ ${type} ] ${detail.reason}`);
  fileUpload.addEventListener('six-file-upload-failure', showEvent);
</script>

Multiple File Upload

You can upload multiple files via the multiple attribute.

html
<six-file-upload id="six-file-upload-success-id-2" multiple></six-file-upload>
<six-file-list id="six-file-list-2"> </six-file-list>

<script type="module">
  const fileUpload = document.getElementById('six-file-upload-success-id-2');
  const fileList = document.getElementById('six-file-list-2');
  let counter = 0;

  fileUpload.addEventListener('six-file-upload-success', ({ detail }) => {
    const files = detail.files;

    for (const file of files) {
      const item = Object.assign(document.createElement('six-file-list-item'), {
        id: String(counter++),
        name: file.name,
        size: file.size,
        date: new Date().toLocaleDateString(),
      });

      item.addEventListener('six-file-list-item-remove', ({ detail }) => {
        const childToRemove = fileList.querySelector(`[name="${detail.name}"]`);
        fileList.removeChild(childToRemove);
      });

      item.addEventListener('six-file-list-item-download', ({ detail }) => {
        alert(`download file ${detail.name}`);
      });

      fileList.append(item);
    }
  });

  const showEvent = ({ type, detail }) => alert(`[ ${type} ] ${detail.reason}`);
  fileUpload.addEventListener('six-file-upload-failure', showEvent);
</script>

Label

You can define a custom label via the label attribute

html
<six-file-upload label="some custom label"></six-file-upload>

Disabled File Upload

html
<six-file-upload disabled></six-file-upload>

Compact File Upload

html
<six-file-upload compact></six-file-upload>

Uploading

html
<six-file-upload uploading></six-file-upload>

Invalid with error text

The error-text prop accepts either a simple string message, or a list of messages. If invalid, all of them will be displayed.

html
<six-file-upload           id="invalid-with-errors"
  invalid
  error-text="This is a simple string message"
></six-file-upload>
<script type="module">
  const sixInput = document.getElementById('invalid-with-errors');
  sixInput.errorText = ['File is too large', 'Message 2'];
  sixInput.errorTextCount = 3;
</script>

Invalid with error slot

When using the error-text slot, it is recommended to use the six-error component to wrap the error message(s). This will provide the correct styling out of the box.

An error message with a link
html
<six-file-upload invalid="false">
  <div slot="error-text">
    <six-error               >An error message
      <a href="https://github.com/six-group/six-webcomponents" target="_blank">with a link</a></six-error>
  </div>
</six-file-upload>

Properties

PropertyAttributeDescriptionTypeDefault
acceptacceptAccepted MIME-Types.string | undefinedundefined
compactcompactSet to true if file control should be small.booleanfalse
disableddisabledSet when button is disabled.booleanfalse
errorTexterror-textThe error message shown, if invalid is set to true.string | string[]''
invalidinvalidIf this property is set to true and an error message is provided by errorText, the error message is displayed.booleanfalse
labellabelLabel of the drop area.string | undefinedundefined
maxFileSizemax-file-sizeAllowed max file size in bytes.number | undefinedundefined
multiplemultipleMore than one file allowed.booleanfalse
uploadinguploadingSet to true to draw the control in a loading state.booleanfalse

Events

EventDescriptionType
six-file-upload-failureTriggers when an uploaded file doesn't match MIME type or max file size.CustomEvent<SixFileUploadFailurePayload>
six-file-upload-successTriggers when a file is added.CustomEvent<IMultipleFiles | ISingleFile>

Slots

SlotDescription
"error-text"Error text that is shown when the status is set to invalid. Alternatively, you can use the error-text prop.

Dependencies

Depends on

Graph


Copyright © 2021-present SIX-Group