0

When I try to use aws.s3(), everything works fine, my bucket is created with the appropriate key.

var s3 = new AWS.S3();

    // Create a bucket and upload something into it
    var bucketName = 'node-sdk-sample-' + uuid.v4();
    var keyName = 'hello';

    s3.createBucket({Bucket: bucketName}, function() {
      var params = {Bucket: bucketName, Key: keyName,ACL: 'public-read'};
      s3.putObject(params, function(err, data) {
        if (err)
          console.log(err)
        else
          console.log("Successfully uploaded data to " + bucketName + "/" + keyName);
      });
    });

But When I try to upload a multipart data with multer-3s , I get the error: Access Denied.

var aws = require('aws-sdk')
var uuid = require('node-uuid')
var multer= require('multer')
var multerS3 = require('multer-s3')
var s3 = new aws.S3()
var bucket = 'BucketWAR' + uuid.v4()
var upload = multer({
    storage: multerS3({
        s3: s3,
        bucket: 'some-bucket',
        acl: 'public-read',
        key: function (req, file, cb) {
            cb(null, Date.now().toString())
        }
    })
})
router.get('/index', indexController.idex)
router.post('/uploadFile', upload.single('file'), function (req, res, next) {
    res.send("Uploaded!");
});

I can't fix this. Do I need Policy? But I didn't need it for putObject. What is the mean difference?

codeGeass
  • 810
  • 11
  • 19
  • I don't know what `var bucket = 'BucketWAR' + uuid.v4()` is supposed to do, but it can't be correct. – Michael - sqlbot Jul 16 '17 at 01:31
  • this enables a unique name to the bucket but the problem was so silly : after defining bucket I didn't use it: bucket: 'some-bucket' I must put: bucket: bucket that I have defined by bucket = 'BucketWAR' + uuid.v4() – codeGeass Jul 17 '17 at 09:50

1 Answers1

0

Everything is correct except that I didn't use the right variable, silly problem, after defining bucket I didn't use it:

  • bucket: 'some-bucket'

    I must put:

  • bucket: bucket

    that I have defined by bucket = 'BucketWAR' + uuid.v4()

Community
  • 1
  • 1
codeGeass
  • 810
  • 11
  • 19