main.js 909 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. 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: data.fields
  35. }
  36. })
  37. }
  38. })