admin管理员组文章数量:1357402
I am trying to upload a video file from JS to an S3 bucket but am getting a 400 bad request right now. I am sure I set up everything properly but could of done something.
I generate a URL on a server like this:
const client = new S3({
accessKeyId: 'id-ommited',
secretAccessKey: 'key-ommited',
region: 'eu-west-2',
useAccelerateEndpoint: true
});
const url = client.getSignedUrl('putObject', {
Bucket: 'screen-capture-uploads',
Key: 'video.webm',
Expires: 60 * 60,
ContentType: 'application/octet-stream'
});
This URL appears to be fine on my frontend which I put through to an XMLHttpRequest like so
const xhr = new XMLHttpRequest();
xhr.open('PUT', body.url); // body.url being the presigned url
xhr.setRequestHeader('x-amz-acl', 'public-read');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.send(blob); // blob being the webm binary
I am using a CORS setup that just allows PUT from anywhere
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
I checked that and it works fine. Also the IAM user has permission to put to the bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::screen-capture-uploads/*"
]
}
]
}
I managed to solve my issues up to this point. I've looked at some other answers but didn't find anything useful for me. Anybody got any ideas for me?
I am trying to upload a video file from JS to an S3 bucket but am getting a 400 bad request right now. I am sure I set up everything properly but could of done something.
I generate a URL on a server like this:
const client = new S3({
accessKeyId: 'id-ommited',
secretAccessKey: 'key-ommited',
region: 'eu-west-2',
useAccelerateEndpoint: true
});
const url = client.getSignedUrl('putObject', {
Bucket: 'screen-capture-uploads',
Key: 'video.webm',
Expires: 60 * 60,
ContentType: 'application/octet-stream'
});
This URL appears to be fine on my frontend which I put through to an XMLHttpRequest like so
const xhr = new XMLHttpRequest();
xhr.open('PUT', body.url); // body.url being the presigned url
xhr.setRequestHeader('x-amz-acl', 'public-read');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.send(blob); // blob being the webm binary
I am using a CORS setup that just allows PUT from anywhere
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws./doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
I checked that and it works fine. Also the IAM user has permission to put to the bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::screen-capture-uploads/*"
]
}
]
}
I managed to solve my issues up to this point. I've looked at some other answers but didn't find anything useful for me. Anybody got any ideas for me?
Share Improve this question asked Jul 16, 2019 at 13:34 Reece WardReece Ward 2231 gold badge2 silver badges9 bronze badges 1- Man, you are god! I just changed the content-type and it worked like a charm – Ganesh Chowdhary Sadanala Commented May 12, 2024 at 2:34
1 Answer
Reset to default 4I went and got the endpoint it produced and just put it straight in the browser. Turns out I hadn't enabled transfer acceleration on the bucket I was using!
This just turned into a bad request without any extra information
本文标签: javascript400 Bad Request from PUT to S3 using presigned URLStack Overflow
版权声明:本文标题:javascript - 400 Bad Request from PUT to S3 using pre-signed URL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744038782a2580272.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论