获取文件的公共 URL - Google Cloud Storage - App Engine (Python) [英] Get Public URL for File - Google Cloud Storage - App Engine (Python)

查看:37
本文介绍了获取文件的公共 URL - Google Cloud Storage - App Engine (Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有与 getPublicUrl PHP 方法等效的 Python?>

Is there a python equivalent to the getPublicUrl PHP method?

$public_url = CloudStorageTools::getPublicUrl("gs://my_bucket/some_file.txt", true);

我正在使用适用于 Python 的 Google Cloud 客户端库存储一些文件,并且我正在尝试找出一种以编程方式获取我正在存储的文件的公共 URL 的方法.

I am storing some files using the Google Cloud Client Library for Python, and I'm trying to figure out a way of programatically getting the public URL of the files I am storing.

推荐答案

Daniel, Isaac - 谢谢你们.

Daniel, Isaac - Thank you both.

在我看来,Google 故意让您不要直接从 GCS 提供服务(带宽原因?不知道).因此,根据文档的两种选择是使用 Blobstore 或 Image Services(图像).

It looks to me like Google is deliberately aiming for you not to directly serve from GCS (bandwidth reasons? dunno). So the two alternatives according to the docs are either using Blobstore or Image Services (for images).

我最终做的是使用 blobstore 提供文件超过 GCS.

What I ended up doing is serving the files with blobstore over GCS.

为了从 GCS 路径获取 blobstore 密钥,我使用了:

To get the blobstore key from a GCS path, I used:

blobKey = blobstore.create_gs_key('/gs' + gcs_filename)

然后,我在服务器上暴露了这个网址——主.py:

Then, I exposed this URL on the server - Main.py:

app = webapp2.WSGIApplication([
...
    ('/blobstore/serve', scripts.FileServer.GCSServingHandler),
...

文件服务器.py:

class GCSServingHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self):
        blob_key = self.request.get('id')
        if (len(blob_key) > 0):
            self.send_blob(blob_key)
        else: 
            self.response.write('no id given')

这篇关于获取文件的公共 URL - Google Cloud Storage - App Engine (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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