uppy/examples/aws-presigned-url/main.js
Renée Kooi dfb23e58a6
website,examples: set a content-type header for S3 presigned PUT uploads
As suggested by @trumpet2012. Thanks!

Closes #1233
2019-09-23 15:22:44 +02:00

40 lines
918 B
JavaScript

const Uppy = require('@uppy/core')
const Dashboard = require('@uppy/dashboard')
const AwsS3 = require('@uppy/aws-s3')
const uppy = 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
}
})
}
})