How do you get or generate a URL to the object in a bucket?

末鹿安然 提交于 2020-01-01 01:57:51

问题


I'm storing objects in buckets on google cloud storage. I would like to provide a http url to the object for download. Is there a standard convention or way to expose files stored in cloud storage as http urls?


回答1:


Yes. Assuming that the objects are publicly accessible:

http://BUCKET_NAME.storage.googleapis.com/OBJECT_NAME

You can also use:

http://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME

Both HTTP and HTTPS work fine. Note that the object must be readable by anonymous users, or else the download will fail. More documentation is available at https://developers.google.com/storage/docs/reference-uris

If it is the case that the objects are NOT publicly accessible and you only want the one user to be able to access them, you can generate a signed URL that will allow only the holder of the URL to download the object, and even then only for a limited period of time. I recommend using one of the GCS client libraries for this, as it's easy to get the signing code slightly wrong: https://developers.google.com/storage/docs/accesscontrol#Signed-URLs




回答2:


One way is to use https://storage.cloud.google.com// see more documentation at https://developers.google.com/storage/docs/collaboration#browser



来源:https://stackoverflow.com/questions/20478369/how-do-you-get-or-generate-a-url-to-the-object-in-a-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!