gpt4 book ai didi

javascript - 使用预签名 URL 从 PUT 到 S3 的 400 错误请求

转载 作者:行者123 更新时间:2023-12-02 23:18:25 24 4
gpt4 key购买 nike

我正在尝试将视频文件从 JS 上传到 S3 存储桶,但现在收到 400 错误请求。我确信我已经正确设置了所有内容,但我可以做一些事情。

我在服务器上生成一个 URL,如下所示:

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'
});

这个 URL 在我的前端似乎没问题,我将其传递给 XMLHttpRequest,如下所示

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

我使用的 CORS 设置只允许从任何地方进行 PUT

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

我检查了一下,效果很好。此外,IAM 用户有权放入存储桶

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::screen-capture-uploads/*"
]
}
]
}

到目前为止我已经成功解决了我的问题。我看过其他一些答案,但没有发现任何对我有用的东西。有人对我有什么想法吗?

最佳答案

我去获取了它生成的端点,然后将其直接放入浏览器中。原来我没有在我使用的存储桶上启用传输加速!

这只是一个错误的请求,没有任何额外的信息

关于javascript - 使用预签名 URL 从 PUT 到 S3 的 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57058519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com