0

Slingshot package is used with Meteor to upload images to S3 directly from the client. Same code that I've used in other projects approved to be working. Even at my local setup, I can upload images to cloud, but not with its deployed version, which is identical. The error is as follows:

Failed to upload file to cloud storage [Bad Request - 400]

the region 'us-east-1' is wrong; expecting 'eu-central-1' (but it doesn't tell where...)

Any ideas?

This is the initialisation of the Meteor Slingshot directive:

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;
  }
});

This is my Amazon S3 CORS configuration:

<?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>

I have no bucket policy. Access control is all public.

Help appreciated.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Emo
  • 580
  • 1
  • 8
  • 27
  • how are you configuring the s3 client? – Daniel A. White Jul 09 '18 at 01:38
  • @DanielA.White Like noted in this below link, I add them to the `createDirective` method. I did have the region there as well... And like I said before, it works locally. https://github.com/CulturalMe/meteor-slingshot#add-meta-context-to-your-uploads – Emo Jul 09 '18 at 11:51
  • please provide a [mcve] – Daniel A. White Jul 09 '18 at 13:07
  • This is probably an error in the S3 client configuration, not a CORS error. Can you post your S3 client initialization code? – coagmano Jul 09 '18 at 23:19
  • I just added it. Please note that the upload works flawlessly on my local setup, which is identical to what I deploy... – Emo Jul 10 '18 at 20:15

1 Answers1

0

The problem was me. I defined the region in my settings as AWSregion (r), whereas I called it AWSRegion (R) in my code to setup. So it was undefined and didn't work.

The solution is to make sure cases are typed right.

Emo
  • 580
  • 1
  • 8
  • 27