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 개의 파일이있을 때 Exx는 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'))); 
관련 문제