使用 S3FS 节点 js 库时无法为上传的文件分配 ACL 权限

Unable to assign ACL permissions to uploaded file when using S3FS node js lib

我正在使用 S3FS 库(在 node.js 应用程序中)将文件上传到我的 AWS S3 目录。 (参考文档 https://www.npmjs.com/package/s3fs) and

s3fs 对象初始化
s3fsImpl = new s3fs(bucketPath, { accessKeyId: xxxxx, secretAccessKey: xxxxx, ACL: 'public-read' })

方法写入文件:s3fsImpl.writeFile(fileName, stream)
文件已成功上传,我收到 "ETag" 作为响应。但是,上传的文件无法访问 publicly。

如何授予适当的 ACL 权限以使其可供 public-read 访问?

您可以提供 ACL 作为 writeFile 方法中的第三个选项,如

s3fsImpl.writeFile(fileName, stream,{ ACL: 'public-read'})

实际上,我能够在节点中使用以下方法实现此功能

第一步: 安装并包含 "aws-sdk" 以访问 aws 资源(我将其用于 S3)

var AWS = require('aws-sdk')
var s3 = new AWS.S3()

第 2 步:

s3.putObject({
            Bucket: AWS_BUCKET_NAME, // bucket name on which file to be uploaded
            Key: uploadKey,  // file name on s3
            ContentType: file.type, // type of file
            Body: new Buffer(fileData, 'binary'), // base-64 file stream
            ACL: 'public-read'  // public read access
        }, function (err, resp) {
            if (err) {  // if there is any issue
                console.error('failed file upload to S3:: ', err)
                callback(err, null)
            }
            console.log('response from S3: ', resp)
            callback(null, 'Success')
        }
    )

ACL:'public-read' 将在 S3

上分配 public 对您的 media/file 的读取权限