amazon-s3 - Slingshot 无法上传到 S3
问题描述
Slingshot 包与 Meteor 一起使用,可以直接从客户端将图像上传到 S3。我在其他获准工作的项目中使用的相同代码。即使在我的本地设置中,我也可以将图像上传到云端,但不能使用其部署的版本,这是相同的。错误如下:
Failed to upload file to cloud storage [Bad Request - 400]
the region 'us-east-1' is wrong; expecting 'eu-central-1'
(但它没有告诉你在哪里......)
有任何想法吗?
这是 Meteor Slingshot 指令的初始化:
const s3Settings = Meteor.settings.private.S3settings;
Slingshot.createDirective("userProfileImages", Slingshot.S3Storage, {
AWSAccessKeyId: s3Settings.AWSAccessKeyId,
AWSSecretAccessKey: s3Settings.AWSSecretAccessKey,
bucket: s3Settings.AWSBucket,
region: s3Settings.AWSRegion,
acl: "public-read",
authorize: function () {
if (!this.userId) {
const message = "Please login before posting images";
throw new Meteor.Error("Login Required", message);
}
return true;
},
key: function (file) {
const user = Meteor.users.findOne(this.userId);
return user.username + "/" + file.name;
}
});
这是我的 Amazon S3 CORS 配置:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>10000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
我没有存储桶策略。访问控制都是公开的。
帮助表示赞赏。
解决方案
问题是我。我在设置中将区域定义为AWSregion
( r
),而我在代码中将其称为AWSRegion
( R
) 以进行设置。所以它是未定义的并且没有工作。
解决方案是确保案例输入正确。
推荐阅读
- oracle-apex - 如何在 Oracle Apex 上为社交登录用户添加授权角色?
- javascript - Javascript 正则表达式匹配自定义标签外部/内部问题
- github-actions - 在 with 块中使用定义的环境变量进行 github 操作
- java - 键正确时由于 ClassCastException 而无法在 Java 中打印 LinkedHasMap
- javascript - 表单元素上的自定义引导验证
- php - Axios/Vue:如何判断 Axios 是否正常工作?
- python - ERROR Utils: Aborting task java.lang.UnsupportedOperationException: PrimitiveType coder: unsupported data type null
- google-apps-script - 将谷歌表格中的多行数据更新为谷歌表单的多个部分
- java - Java 变量不会被不同的实例/线程更新
- powershell - 获取所有文件的目录名、文件夹名和个数