如何获取或生成存储桶中对象的 URL? [英] How do you get or generate a URL to the object in a bucket?

查看:27
本文介绍了如何获取或生成存储桶中对象的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将对象存储在谷歌云存储上的存储桶中.我想为该对象提供一个 http url 以供下载.是否有标准约定或方式将存储在云存储中的文件公开为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆