0
我正在上傳配置文件圖像到谷歌雲存儲(這工作正常),並試圖使所有的圖像公開可用,但是我一直從返回403錯誤IMG SRC或者只是在瀏覽器中粘貼它的內部使用URL時,返回的URL看起來如下:Nodejs Google雲存儲在訪問公開網址時返回403
https://storage.googleapis.com/my_bucket_name/12370691_1205162746164520_2152367844899316112_o.jpg
,它提供了以下錯誤:
Anonymous users does not have storage.objects.get access to object my_bucket_name/15991995_384418798568801_734448169_o.jpg.
note: my_bucket_name is not the real bucket name, it's just a placeholder for this post
代碼BEL流顯示瞭如何設置谷歌雲儲存起來:
const gcs = require('@google-cloud/storage')({
projectId: ‘my_project_id’,
keyFilename: './routes/to/my/keyfile.json'
});
const bucket = gcs.bucket(‘my_bucket_name’);
const options = {
entity: 'allUsers',
role: gcs.acl.READER_ROLE
};
bucket.acl.add(options, (err, aclObject) => {
console.log(err); //null
console.log(aclObject); //{ entity: 'allUsers', role: 'READER' }
});
function getPublicUrl(filename) {
return `https://storage.googleapis.com/${bucketName}/${filename}`;
}
... code for uploading the image below, (works fine)