【发布时间】:2018-12-16 12:50:42
【问题描述】:
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>
我没有存储桶策略。 访问控制是公开的。
帮助表示赞赏。
【问题讨论】:
-
你是如何配置 s3 客户端的?
-
@DanielA.White 就像在下面的链接中指出的那样,我将它们添加到
createDirective方法中。我确实在那里也有该地区......就像我之前所说的,它在当地有效。 github.com/CulturalMe/… -
投反对票?为什么?..
-
这可能是 S3 客户端配置中的错误,而不是 CORS 错误。您可以发布您的 S3 客户端初始化代码吗?
标签: amazon-s3 meteor meteor-slingshot react-slingshot