main.js 944 B

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