main.js 887 B

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