使用multer -s3亚马逊服务器图像上传错误访问被拒绝

时间:2016-08-04 13:54:27

标签: node.js multer-s3

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)

3 个答案:

答案 0 :(得分:1)

  

我通过转到S3网站上的AWS帐户并在full access标签下向公众提供Permissions来解决了这个问题。 (

不建议使用AWS所说的方法,但这是我找到的唯一方法,可以完成它

答案 1 :(得分:0)

您需要使用IAM创建以下策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::your-bucket-name-here/*"
        }
    ]
}

答案 2 :(得分:0)

即使我遇到了同样的问题,我也解决了。

对我来说,这个问题的原因是我一直在将 acl(访问控制列表)键 acl: 'public-read' 传递给 multerS3 对象参数。

ACL 密钥区分大小写,使用 acl: 'public-read' 而不是使用 ACL: 'public-read' 工作正常。

如果您没有在 multerS3 对象参数中传递 ACL 属性也可以。

如果未指定 ACL,则默认使用 ACL: 'private'

存储文件

AWS 支持以下选项:

ACL:私有 |公众阅读|公共读写| aws-exec-read |认证读取|桶所有者阅读|存储桶所有者完全控制

multerS3 和 acl(拒绝访问):

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 与 ACL(工作正常):

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