dennis
dennis

Reputation: 153

slingshot meteor s3 error

I’m afraid I don’t understand how this is supposed to work at all. How does slingshot know the address to find my s3 bucket? Is this completely determined by the access keys?

This is the code I have in my server/files.js:

var imageDetails = new Mongo.Collection('images');

Slingshot.fileRestrictions("myImageUploads", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
  maxSize: 2 * 1024 * 1024,
});


Slingshot.createDirective("myImageUploads", Slingshot.S3Storage, {
AWSAccessKeyId: "AWSAccessKeyId",
AWSSecretAccessKey: "AWSSecretAccessKey",
bucket: "mybucketname",
acl: "public-read",
region: "us-west-1",

authorize: function () {
  if (!this.userId) {
    var message = "Please login before posting images";
    throw new Meteor.Error("Login Required", message);
  }
  return true;
  },

  key: function (file) {
    var currentUserId = Meteor.user().emails[0].address;
    return currentUserId + "/" + file.name;
   }
    });

And this is my settings.json file

{
  "AWSAccessKeyId" : "my access key",
  "AWSSecretAccessKey" : "my secret access key",
  "AWSBucket" : "mybucketname"

}

I get this error in my browser:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mybucketname.s3-us-west-1.amazonaws.com/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

But I have a CORS configuration in my theportdata bucket.

The first step, I guess, is there any way to check if my application is making contact at all with my s3 bucket? Like I said, I don’t really understand how slingshot finds the bucket.

Upvotes: 0

Views: 114

Answers (1)

dennis
dennis

Reputation: 153

SOLVED Changed "region: us-west-1" to "region: us-west-2" and it works. There is also no need for the AWSAccessKeyId and AWSSecretAccessKey, since slingshot finds this automatically from settings.json. Apparently all that's needed for an address is the bucket name and the region. https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

Upvotes: 1

Related Questions