GCS,只有登录的用户才能看到我的马赛克中的图像

时间:2019-11-26 18:16:59

标签: python google-cloud-storage

我正在使用Google云存储构建马赛克,并将用户上传的图像存储在存储桶中。但是,要查看任何图像,您必须先登录(一个Google帐户)。我已将存储桶设置为公共,并且任何已经登录的用户都可以查看该图像。但是我希望图像即使没有登录也能显示出来。我该怎么办? 我将图片的网址存储在数据库中:

#this part is the return function of my image upload
imageurl= 'https://storage.cloud.google.com/fortest098.appspot.com/{}'.format(mosaicLocation)

# and this is how i put my image into the database:
ImageInfo(...,image_url=imageurl).put

我想获取公共网址或其他内容吗?

1 个答案:

答案 0 :(得分:0)

默认情况下,上传到GCS的默认对象受访问控制。 您可以通过在上传时或上传后设置一个预定义的Acl来使对象公开可读(例如,参见https://cloud.google.com/storage/docs/json_api/v1/objects/update)。 您也可以使用gsutil命令执行此操作:

gsutil acl set public-read gs://your-bucket/your-object