Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using multer -s3 amazon server image upload error access denied

AccessDenied: Access Denied
    at Request.extractError (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/services/s3.js:524:35)
    at Request.callListeners (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:615:14)
    at Request.transition (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:617:12)
    at Request.callListeners (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:615:14)
    at Request.transition (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/cricket_game/node_modules/multer-s3/node_modules/s3fs/node_modules/aws-sdk/lib/request.js:38:9)
like image 528
Jay Jariwala Avatar asked Aug 04 '16 13:08

Jay Jariwala


3 Answers

Even I was facing the same issue and I got it resolved.

For me the cause for this issue was I have been passing acl (Access control lists) key acl: 'public-read' to the multerS3 object params.

ACL key is case sensitive, instead of using acl: 'public-read' using ACL: 'public-read' worked fine.

Its ok if you didn't pass the ACL property in multerS3 object params.

If ACL not specified, then default is to store the file with ACL: 'private'

AWS supports the following options:

ACL: private | public-read | public-read-write | aws-exec-read | authenticated-read | bucket-owner-read | bucket-owner-full-control

multerS3 with acl (Access denied):

var upload = multer({
   storage: multerS3({
        s3: s3,
        acl: 'public-read',
        bucket: BucketName,
        key: function (req, file, cb) {
            cb(null, new Date().toISOString() + '-' + file.originalname);
        }
    })
});

multerS3 with ACL (Works fine):

var upload = multer({
    storage: multerS3({
        s3: s3,
        ACL: 'public-read',
        bucket: BucketName,
        key: function (req, file, cb) {
            cb(null, new Date().toISOString() + '-' + file.originalname);
        }
    })
});
like image 106
Umesh K Avatar answered Nov 20 '22 19:11

Umesh K


I solved this issue by going to my S3 Account in AWS Website and give full access to the public under Permissions tab. (

By the way it's not recommended as AWS said but it's the only way I found so that I get it done)

like image 27
Ahmad Khoja Avatar answered Nov 20 '22 20:11

Ahmad Khoja


You need to create the following policy using IAM:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::your-bucket-name-here/*"
        }
    ]
}
like image 2
Wédney Yuri Avatar answered Nov 20 '22 19:11

Wédney Yuri