1

このコードが正常に動作する別のプロジェクトがありますので、今回はこの設定を忘れてしまったかもしれません。私はfirebaseのストレージにアクセスするためにGoogleのクラウドAPIを使用しています。ファイルが存在することを確認した後にGoogleクラウド404

便宜上、ファイルとなります。

var storage = require('@google-cloud/storage')({ 
 
\t \t keyFilename: 'serviceAccountKey.json', 
 
\t \t projectId: 'my-id' 
 
\t }); 
 
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) { 
 
    \t console.log("File exists. Printing."); //prints "File exists. Printing." 
 
    \t file.download().then(function(currentFileData) { 
 
    \t \t console.log("This line is never reached."); 
 
    \t }).catch(err => { 
 
    \t \t console.error('ERROR:', err); //gives a 404 error 
 
    \t }); 
 
     } 
 
});

の代わりに印刷し、それは以下のキャッチエラーを出力します「この行は到達しません。」: 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 ... ...フルエラーが巨大であるので、私はその中でそれをここに投稿しないだろう必要な場合を除いて完全です。

+0

バケットはプロジェクトに関連付けられています。両方のプロジェクトで、同じディレクトリに同じファイルがあることは確かですか? – MondKin

+0

はい、私は確信しています。私はX個のファイルを持っています(最大8個)、このコードを変更するファイル変数で再実行します。私は3つのファイルを持っていると3回実行します(存在が3回真であるため)。しかし、3回エラーが発生します。 –

+0

Google Cloudのドキュメントを確認しても、コードに問題はないと思われるので、バケツのパーミッションの問題だと思うだけで、ファイルのリストを表示できますが、ファイルの内容にアクセスできません。 – MondKin

答えて

0

ファイルにアクセスしようとしているユーザーだけがバケットを介してアクセスできますが、ファイルはアクセスできません。両方のプロジェクトにバケットとファイルの両方のACLをチェックし、何を得るの比較:

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

あなたはこのような出力が表示されるはずです。何の差が存在しない場合、してみてください

[ [ { entity: '[email protected]', role: 'OWNER' }, 
    { entity: '[email protected]', 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'))); 
関連する問題