Answers for "uppy get data to input"

0

uppy get data to input

const uppy = new Uppy(...)
const fileInput = document.querySelector('#my-file-input')

fileInput.addEventListener('change', (event) => {
  const files = Array.from(event.target.files)

  files.forEach((file) => {
    try {
      uppy.addFile({
        source: 'file input',
        name: file.name,
        type: file.type,
        data: file
      })
    } catch (err) {
      if (err.isRestriction) {
        // handle restrictions
        console.log('Restriction error:', err)
      } else {
        // handle other errors
        console.error(err)
      }
    }
  })
})

// it’s probably a good idea to clear the `<input>`
// after the upload or when the file was removed
// (see https://github.com/transloadit/uppy/issues/2640#issuecomment-731034781)
uppy.on('file-removed', () => {
  fileInput.value = null
})

uppy.on('complete', () => {
  fileInput.value = null
})
Posted by: Guest on January-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language