Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用S3FS节点js lib时无法为上载的文件分配ACL权限_Node.js_Amazon S3_Acl - Fatal编程技术网

Node.js 使用S3FS节点js lib时无法为上载的文件分配ACL权限

Node.js 使用S3FS节点js lib时无法为上载的文件分配ACL权限,node.js,amazon-s3,acl,Node.js,Amazon S3,Acl,我正在使用S3FS库(在node.js应用程序中)将文件上载到我的AWS S3目录。(参考文件)和 s3fs对象初始化 s3fsImpl=新的s3fs(bucketPath{ accessKeyId:xxxxx, secretAccessKey:xxxxx, ACL:“公共读取” }) 方法writeFile:s3fsImpl.writeFile(文件名,流) 文件上传成功,我得到了“ETag”的回应。但是,上载的文件不能公开访问 如何授予适当的ACL权限以使其可供公众阅读?您可以在write

我正在使用S3FS库(在node.js应用程序中)将文件上载到我的AWS S3目录。(参考文件)和

s3fs对象初始化
s3fsImpl=新的s3fs(bucketPath{
accessKeyId:xxxxx,
secretAccessKey:xxxxx,
ACL:“公共读取”
})

方法writeFile:
s3fsImpl.writeFile(文件名,流)

文件上传成功,我得到了“ETag”的回应。但是,上载的文件不能公开访问


如何授予适当的ACL权限以使其可供公众阅读?

您可以在
writeFile
方法中提供ACL作为第三个选项,如下所示:


s3fsImpl.writeFile(文件名,流,{ACL:'public read'})

事实上,我能够在node中使用以下方法实现此功能

步骤1: 安装并包含“aws sdk”以访问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:“公共读取”将为S3上的媒体/文件分配公共读取权限

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')
        }
    )