index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Uppy from '@uppy/core'
  2. import Dashboard from '@uppy/dashboard'
  3. import Instagram from '@uppy/instagram'
  4. import GoogleDrive from '@uppy/google-drive'
  5. import Url from '@uppy/url'
  6. import Webcam from '@uppy/webcam'
  7. import Tus from '@uppy/tus'
  8. import '@uppy/core/dist/style.css'
  9. import '@uppy/dashboard/dist/style.css'
  10. import '@uppy/url/dist/style.css'
  11. import '@uppy/webcam/dist/style.css'
  12. const TUS_ENDPOINT = 'https://tusd.tusdemo.net/files/'
  13. const uppy = new Uppy({
  14. debug: true,
  15. meta: {
  16. username: 'John',
  17. license: 'Creative Commons',
  18. },
  19. })
  20. .use(Dashboard, {
  21. trigger: '#pick-files',
  22. target: '#upload-form',
  23. inline: true,
  24. metaFields: [
  25. { id: 'license', name: 'License', placeholder: 'specify license' },
  26. { id: 'caption', name: 'Caption', placeholder: 'add caption' },
  27. ],
  28. showProgressDetails: true,
  29. proudlyDisplayPoweredByUppy: true,
  30. note: '2 files, images and video only',
  31. restrictions: { requiredMetaFields: ['caption'] },
  32. })
  33. .use(GoogleDrive, { target: Dashboard, companionUrl: 'http://localhost:3020' })
  34. .use(Instagram, { target: Dashboard, companionUrl: 'http://localhost:3020' })
  35. .use(Url, { target: Dashboard, companionUrl: 'http://localhost:3020' })
  36. .use(Webcam, { target: Dashboard })
  37. .use(Tus, { endpoint: TUS_ENDPOINT })
  38. // You can optinally enable the Golden Retriever plugin — it will
  39. // restore files after a browser crash / accidental closed window
  40. // see more at https://uppy.io/docs/golden-retriever/
  41. //
  42. // .use(GoldenRetriever, { serviceWorker: true })
  43. uppy.on('complete', (result) => {
  44. if (result.failed.length === 0) {
  45. console.log('Upload successful 😀')
  46. } else {
  47. console.warn('Upload failed 😞')
  48. }
  49. console.log('successful files:', result.successful)
  50. console.log('failed files:', result.failed)
  51. })
  52. // uncomment if you enable Golden Retriever
  53. //
  54. /* eslint-disable compat/compat */
  55. // if ('serviceWorker' in navigator) {
  56. // navigator.serviceWorker
  57. // .register('/sw.js')
  58. // .then((registration) => {
  59. // console.log('ServiceWorker registration successful with scope: ', registration.scope)
  60. // })
  61. // .catch((error) => {
  62. // console.log('Registration failed with ' + error)
  63. // })
  64. // }
  65. /* eslint-enable */