【发布时间】:2017-09-06 02:31:24
【问题描述】:
我正在将个人资料图片上传到谷歌云存储(工作正常)并尝试公开所有图片,但是当在 img src 内部使用或只是粘贴时,我不断从返回的 url 中收到 403 错误在浏览器中,返回的 url 如下所示:
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.
注意:my_bucket_name 不是真正的存储桶名称,它只是一个占位符 这篇文章
下面的代码显示了我是如何设置谷歌云存储的:
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)
【问题讨论】:
标签: node.js google-app-engine google-cloud-platform google-cloud-storage