Gcloud ApiError:权限不足,即使相同的API将文件写入存储
我在这里不知所措 我的节点代码成功上传文件到gcloud存储,但似乎无法使文件公开,甚至改变acl。
其实这个文件是用gcloud存储的,但是不能把相同的文件制作成public。
返回的错误是
{[ApiError:Insufficient Permission]错误:[{domain:'global',reason:'insufficientPermissions',message:'Insufficient Permission'}],code:403,message:'Permission Permission',response:undefined}
这里是我的代码(假设这个代码在STREAM中,就是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); } }); });
虽然代码并不直接显示问题,但这可能有所帮助:WRITER 存储桶权限可以创build对象,但是您需要OWNER 对象权限来更改现有对象上的ACL。 另外,对象的创build者不会自动授予OWNER 对象权限(即使他们是存储桶的所有者) – 如果您在创build对象时未指定预定义ACL ,Google Cloud Storage将始终应用存储区的默认值对象ACL到新创build的对象。
因此,两种可能的修复方法是(1)提前在存储桶上设置默认对象 ACL,以将您的应用程序凭证包含为OWNER,或(2)在创build对象时提供预定义的ACL(如“publicRead”), 。
- gcloud预览应用程序部署返回400与消息应用程序引擎服务帐户没有足够的项目权限。 需要开发者或所有者
- 如何使用存储区存储在Google Flex / App引擎环境中提供静态文件?
- gcloud docker 409图像冲突错误与Node.js
- logingcloud node.js
- 将Sails.js项目部署到Google云:“致命错误:无法find本地咕噜声”。
- 在计算引擎上托pipe的nodeJS项目中,在哪里定义datastore-indexes.xml?
- 从本地数据存储检索时未定义的实体键和数据属性
- Google Cloud PubSub – 实现拉
- 如何使用gcloud-node获取Google Cloud Storage文件的URL?