main.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const Uppy = require('uppy/lib/core/Core.js')
  2. const Dashboard = require('uppy/lib/plugins/Dashboard')
  3. const XHRUpload = require('uppy/lib/plugins/XHRUpload')
  4. const AwsS3 = require('uppy/lib/plugins/AwsS3')
  5. const uppy = Uppy({
  6. debug: true,
  7. autoProceed: false
  8. })
  9. uppy.use(Dashboard, {
  10. inline: true,
  11. target: 'body'
  12. })
  13. uppy.use(XHRUpload)
  14. uppy.use(AwsS3, {
  15. getUploadParameters (file) {
  16. // Send a request to our PHP signing endpoint.
  17. return fetch('/s3-sign.php', {
  18. method: 'post',
  19. // Send and receive JSON.
  20. headers: {
  21. accept: 'application/json',
  22. 'content-type': 'application/json'
  23. },
  24. body: JSON.stringify({
  25. filename: file.name,
  26. contentType: `${file.type.general}/${file.type.specific}`
  27. })
  28. }).then((response) => {
  29. // Parse the JSON response.
  30. return response.json()
  31. }).then((data) => {
  32. // Return an object in the correct shape.
  33. return {
  34. method: data.method,
  35. url: data.url,
  36. fields: {}
  37. }
  38. })
  39. }
  40. })
  41. uppy.run()