6
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)
4

3 回答 3

2

我通过转到我的网站S3帐户并在选项卡下向公众提供解决了这个问题。(AWSfull accessPermissions

顺便说一句,不推荐 AWS 说,但这是我找到的唯一方法,以便我完成它)

于 2019-04-01T10:16:27.023 回答
2

即使我面临同样的问题,我也得到了解决。

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

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

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

如果未指定 ACL,则默认存储文件ACL: 'private'

AWS 支持以下选项:

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

带acl的 multerS3 (拒绝访问):

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

带ACL的 multerS3 (工作正常):

var upload = multer({
    storage: multerS3({
        s3: s3,
        ACL: 'public-read',
        bucket: BucketName,
        key: function (req, file, cb) {
            cb(null, new Date().toISOString() + '-' + file.originalname);
        }
    })
});
于 2021-02-24T02:55:15.650 回答
1

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

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::your-bucket-name-here/*"
        }
    ]
}
于 2020-04-29T14:59:55.173 回答