gpt4 book ai didi

reactjs - 将图像上传到 AWS S3 存储桶 ReactJS 时 POST 403 禁止 CORS 响应

转载 作者:行者123 更新时间:2023-12-05 06:08:17 25 4
gpt4 key购买 nike

您好,我正在尝试使用名为 react-s3 的 NPM 包将图像从我的 React 应用程序上传到 AWS S3。我正在使用 AWS Educate 账户并正确设置了访问 key 和 key 。在我选择图像和控制台记录输出后,它给我一个 403 forbidden 错误,如下所示。

发布https://shopkartimages.s3.amazonaws.com/ 403(禁止)

Response {type: "cors", 
url: "https://shopkartimages.s3.amazonaws.com/",
redirected: false,
status: 403, ok:
false, …}
body: (...)
bodyUsed: false
headers: Headers
__proto__: Headers
ok: false
redirected: false
status: 403
statusText: "Forbidden"
type: "cors"
url: "https://shopkartimages.s3.amazonaws.com/"
__proto__: Response

我的桶策略如下:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Permissions",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": "arn:aws:s3:::shopkartimages/*"
}
]
}

我在S3中的CORS配置如下:

[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2"
],
"MaxAgeSeconds": 3000
}
]

最佳答案

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Permissions",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": "arn:aws:s3:::shopkartimages/*"
}
]
}

您的存储桶策略仅允许GetList 操作。上传文件是一个 PUT 操作。

关于reactjs - 将图像上传到 AWS S3 存储桶 ReactJS 时 POST 403 禁止 CORS 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65146133/

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