reactjs - 使用 Next js 将文件上传到 s3 存储桶
问题描述
使用下一个 js 将文件上传到 s3 存储桶得到 cors 错误
Access to fetch at 'https://*****.s3-us-***.amazonaws.com/' from origin 'http://*****.amazonaws.com:8900' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
没有得到任何适当的解决方案如何解决此类错误,并且还提供了 s3 存储桶中的跨域资源共享 (CORS) 是他们在本地机器上解决此类错误的任何方法
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2"
],
"MaxAgeSeconds": 3000
}
]
在选择文件时需要将文件上传到 s3 存储桶下面是我的上传代码
aws.config.update({
accessKeyId: "##",
secretAccessKey: "###",
region: "###",
signatureVersion: 'v4',
});
const s3 = new aws.S3();
const params = {
Bucket: '####', // pass your bucket name
Key: 'Zip/'+fileName, // file will be saved as testBucket/contacts.csv
ContentType: 'application/zip',
Body: data,
};
s3.upload(params, function(s3Err, data) {
if (s3Err) throw s3Err
console.log(`File uploaded successfully at ${data.Location}`)
});
提前致谢
解决方案
推荐阅读
- php - laravel 中的唯一验证
- javascript - 对表执行计数
- sql - SQL Oracle 到 SQL Server
- asp.net - 预编译 aspx 和 cshtml 页面,但保留主页面或布局页面可更新
- python - PyEDA - 替换表达式中的节点
- regex - 如何为 0.1 到 30.0 的范围创建正则表达式?
- excel - VBA - Worksheet.activate 不工作
- sql - WHERE 子句中的 SQL if-else 等效项
- html - CSS 最佳实践:DRY
- linux - 当我调用 my.domain.name::5984/_utils/ Couchdb 安装时,我什么也看不到