main.js 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import Uppy from '@uppy/core'
  2. import Dashboard from '@uppy/dashboard'
  3. import AwsS3 from '@uppy/aws-s3'
  4. const uppy = new Uppy({
  5. debug: true,
  6. })
  7. uppy.use(Dashboard, {
  8. inline: true,
  9. target: 'body',
  10. })
  11. uppy.use(AwsS3, {
  12. shouldUseMultipart: false, // The PHP backend only supports non-multipart uploads
  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. headers: data.headers,
  36. }
  37. })
  38. },
  39. })