如何获取或生成存储桶中对象的URL? [英] How do you get or generate a URL to the object in a bucket?
问题描述
我将对象存储在Google云存储中的存储桶中.我想提供该对象的http网址以供下载.是否有标准约定或方法将存储在云存储中的文件显示为http url?
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?
推荐答案
是.假定对象是可公开访问的:
Yes. Assuming that the objects are publicly accessible:
http://BUCKET_NAME.storage.googleapis.com/OBJECT_NAME
您还可以使用:
http://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME
HTTP和HTTPS都可以正常工作.请注意,匿名用户必须可以读取该对象,否则下载将失败.有关更多文档,请访问 https://developers.google.com/storage/docs/reference-uris
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
如果是无法公开访问对象的情况,并且您只希望一个用户能够访问它们,则可以生成一个签名的URL,该URL仅允许该URL的持有者下载该对象,并且即使如此,也只能在有限的时间内进行.我建议为此使用GCS客户端库之一,因为很容易使签名代码略有错误: https ://developers.google.com/storage/docs/accesscontrol#Signed-URLs
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
这篇关于如何获取或生成存储桶中对象的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!