yrsamrith
6/27/2017 - 2:21 AM

Slingshot Meteor in server/main.js

Slingshot Meteor in server/main.js

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

Slingshot.createDirective("imageUpload", Slingshot.S3Storage, {
  AWSAccessKeyId: Meteor.settings.AWSAccessKeyId,
  AWSSecretAccessKey: Meteor.settings.AWSSecretAccessKey,
  bucket: "xxx-bucket",
  acl: "public-read",
  region: "ap-northeast-2",

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

    return true;
  },

  key: function (file) {
    //Store file into a directory by the user's username.
    return "upload/" + file.name;
  }

});