在存储桶中,您可以更改交叉策略https://cloud.google.com/storage/docs/cross-origin https://cloud.google.com/storage/docs/cross-origin我按照以下步骤操作:
在 gsutil 中:
首先,我删除了我最初配置的所有用户的读取权限
gsutil iam ch -d allUsers gs:/myBucketName
我删除了它,因为即使我将 json 配置为仅在 localhost:8080 上提供服务,它也会提供来自其他端口的内容。
然后我按照此处指出的那样使用 gsutil 进行配置https://cloud.google.com/storage/docs/configuring-cors https://cloud.google.com/storage/docs/configuring-cors这个 json 选项:
[{ "origin":["http://localhost:8080"],
"responseHeader":["Content-Type"],
"method":["GET"],
"maxAgeSeconds":0
}]
在 gsutil 中:
gsutil cors set cor.json gs://myBucketName
之后,我使用一个简单的 html 和一个仅包含以下内容的本地服务器:
<html>
<body>
<img src="linkfrombyObject">
</body>
</html>
But I when my broser try to fetch the image, It gets and xml that says:"Anonymous caller does not have storage.objects.get
any idea what could be wrong?