main.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import Uppy from '@uppy/core'
  2. import ThumbnailGenerator from '@uppy/thumbnail-generator'
  3. import FileInput from '@uppy/file-input'
  4. const uppyThumbnails = new Uppy({
  5. id: 'uppyThumbnails',
  6. autoProceed: false,
  7. debug: true,
  8. })
  9. uppyThumbnails.use(ThumbnailGenerator, {})
  10. uppyThumbnails.use(FileInput, { target: '#uppyThumbnails', pretty: false })
  11. uppyThumbnails.on('file-added', (file) => {
  12. const el = document.createElement('p')
  13. el.className = 'file-name'
  14. el.textContent = file.name
  15. document.body.appendChild(el)
  16. })
  17. // Dump errors to the screen so saucelabs shows them in screenshots.
  18. uppyThumbnails.on('thumbnail:error', (file, err) => {
  19. const el = document.createElement('pre')
  20. el.style = 'font: 14pt monospace; background: red; color: white'
  21. el.textContent = `Error: ${err.stack}`
  22. document.body.appendChild(el)
  23. })
  24. uppyThumbnails.on('thumbnail:generated', (file) => {
  25. const img = new Image()
  26. img.src = file.preview
  27. img.className = 'file-preview'
  28. img.style.display = 'block'
  29. document.body.appendChild(img)
  30. })