uppy/examples/aws-php/main.js
Raúl Ibáñez 3f07d79de6
Add example for Uppy with S3 and a Node.js server (#4129)
Co-authored-by: Merlijn Vos <merlijn@soverin.net>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-10-17 16:43:00 -03:00

40 lines
914 B
JavaScript

import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import AwsS3 from '@uppy/aws-s3'
const uppy = new Uppy({
debug: true,
})
uppy.use(Dashboard, {
inline: true,
target: 'body',
})
uppy.use(AwsS3, {
getUploadParameters (file) {
// Send a request to our PHP signing endpoint.
return fetch('/s3-sign.php', {
method: 'post',
// Send and receive JSON.
headers: {
accept: 'application/json',
'content-type': 'application/json',
},
body: JSON.stringify({
filename: file.name,
contentType: file.type,
}),
}).then((response) => {
// Parse the JSON response.
return response.json()
}).then((data) => {
// Return an object in the correct shape.
return {
method: data.method,
url: data.url,
fields: data.fields,
headers: data.headers,
}
})
},
})