我正在使用S3FS lib(在node.js应用程序中)将文件上传到我的AWS S3目录。 (参考文档https://www.npmjs.com/package/s3fs)和stackoverflow answer here
s3fs对象初始化
s3fsImpl = new s3fs(bucketPath, {
accessKeyId: xxxxx,
secretAccessKey: xxxxx,
ACL: 'public-read'
})
方法writeFile:s3fsImpl.writeFile(fileName, stream)
文件上传成功,我得到" ETag"作为回应。但是,上传的文件无法公开访问。
如何提供适当的ACL权限以使其可供公共读取?
答案 0 :(得分:1)
您可以在writeFile
方法
s3fsImpl.writeFile(fileName, stream,{ ACL: 'public-read'})
答案 1 :(得分:1)
实际上我能够在节点
中使用以下方法第1步: 安装并包含" 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上为您的媒体/文件分配公开读取权限