首页 > 解决方案 > 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>

我没有存储桶策略。访问控制都是公开的。

帮助表示赞赏。

标签: amazon-s3meteormeteor-slingshotreact-slingshot

解决方案


问题是我。我在设置中将区域定义为AWSregion( r),而我在代码中将其称为AWSRegion( R) 以进行设置。所以它是未定义的并且没有工作。

解决方案是确保案例输入正确。


推荐阅读