amazon-s3meteormeteor-slingshotreact-slingshot

Slingshot fail to upload to S3


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.


Solution

  • 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.