I'm trying to upload some medias on AWS S3
I have 2 applications :
- A backend that can directly access S3 through AWS SDK
- A frontend that needs to upload some file directly to S3
Here's how it goes :
Frontend ask a Presigned Post url to the backend
Backend call S3 API to get an URL and some fields (Key, Policy etc.)
Frontend get those URL from backend and tries a POST on it request with the appropriate form-data
I get this error :
https://mydomain.or has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Here's my CORS Configuration :
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"https://mydomain.or",
]
}
]
Here's my backend code for the presigned POST :
this.videoService.presignedPost(this.entity).toPromise().then((uploadData) => { //Where I get my URL and fields
this.fileInput.url = uploadData.url;
for (const [key, value] of Object.entries(uploadData.fields)) {
event.formData.append(key, value)
}
this.fileInput.upload();
});
Here's my backend code for the presigned POST :
createPreSignedPost(entityDb) {
let today = new Date();
console.log(entityDb)
return new Promise((resolve, reject) => {
var params = {
Bucket: BUCKET_NAME,
Fields: {
key: my/key/,
success_action_status: '201',
signature_expiration: (new Date(today.getTime() + 15 * 60000))
}
};
s3.createPresignedPost(params, function (err, data) {
if (err) {
console.error('Presigning post data encountered an error', err);
reject(err)
} else {
console.log('The post data is', data);
resolve({url: data.url, fields: data.fields})
}
});
What I tried :
- The request seems to pass with Postman but nothing appears in the bucket
- Tried the same with Chrome-unsafe (Without integrated CORS check)
- Displayed the CORS policy and tried with curl to see what happend
The CORS configuration are OK, and when I check with curl I get blocked even though the Method and Host are allowed in my CORS Configuration.
Am I missing something?
Edit
So I checked the request that was blocked by CORS and used the exact same form-data, headers, etc. in an HTTP Client. It works just fine with the client but my app still gets blocked.