validation文件后,Google云404已存在

我有另一个项目,这个相同的代码工作成功,所以这可能是一些configuration选项,我错过了这一次。 我正在使用谷歌云API来访问Firebase存储。

为了清楚起见,该文件确实存在。

var storage = require('@google-cloud/storage')({ keyFilename: 'serviceAccountKey.json', projectId: 'my-id' }); var bucket = storage.bucket('my-id.appspot.com'); var file = bucket.file('directory/file.json'); //this exists! file.exists(function(err, exists){ console.log("Checking for challenges file. Results:" + exists + ", err:" + err); //returns "Checking for challenges file. Results:true, err:nil" if (exists) { console.log("File exists. Printing."); //prints "File exists. Printing." file.download().then(function(currentFileData) { console.log("This line is never reached."); }).catch(err => { console.error('ERROR:', err); //gives a 404 error }); } }); 

ERROR: { ApiError: Not Found at Object.parseHttpRespMessage (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:156:33) at Object.handleResp ... ...完整的错误是巨大的,所以我不会在这里完整发布,除非需要。

试图访问文件的用户可能只能访问存储桶,而不能访问文件。 检查两个项目中的存储桶和文件的ACL,并比较所得到的结果:

 myBucket.acl.get() .then(acls => console.log("Bucket ACLs:", acls)); myFile.acl.get() .then(acls => console.log("File ACLs:", acls)); 

你应该看到这样的输出:

 [ [ { entity: 'user-abenavides333@gmail.com', role: 'OWNER' }, { entity: 'user-dwilches@gmail.com', role: 'OWNER' } ], { kind: 'storage#objectAccessControls', items: [ [Object], [Object] ] } ] 

如果没有差异,请尝试使用相同代码的以下更详细的版本:

 myBucket.acl.get() .then(acls => console.log("Bucket ACLs:", JSON.stringify(acls, null, '\t'))); myFile.acl.get() .then(acls => console.log("File ACLs:", JSON.stringify(acls, null, '\t')));