我在这里不知所措。我的节点代码已成功将文件上传到 gcloud 存储,但似乎无法公开文件,甚至无法更改 acl。
事实是该文件已写入 gcloud 存储,但无法将同一文件公开。
返回的错误是
{ [ApiError: Insufficient Permission] 错误:[ { 域:'global',原因:'insufficientPermissions',消息:'Insufficient Permission'}],代码:403,消息:'Insufficient Permission',响应:未定义}
这是我的代码(假设此代码在 STREAM ergo stdout.pipe 中)
var gcs = GLOBAL.gcloud.storage();
var bucket = gcs.bucket(GLOBAL.storage_names.products);
var file = bucket.file('images/'+targetValue+'_'+filename);
stdout.pipe(file.createWriteStream())
.on('error', function(err) {
var msg = {
"status":"Error"
"err":err
};
console.log(msg);
})
.on('finish', function() {
// The file upload is complete.
console.log("Successfully uploaded "+targetValue+'_'+filename);
file.acl.add({
entity: 'allUsers',
role: gcs.acl.READER_ROLE
}, function(err, aclObject) {
if(err==null)
{
//stream upload file
file.makePublic();
}else{
console.log("ERROR in ACL Adding");
console.log(err)
}
});
file.makePublic(function(err, apiResponse) {
if(err==null)
{
console.log("File made public");
}else{
console.log("make public error");
console.log(err);
}
});
});