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

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

问题描述

是否有一个与getPublicUrl等价的Python PHP方法

Is there a python equivalent to the getPublicUrl PHP method?

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

我正在使用适用于Python的Google Cloud Client库存储一些文件,并且试图计算可以以编程方式获取我存储的文件的公共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.

推荐答案

以撒(Isaac)丹尼尔-谢谢你们。

Daniel, Isaac - Thank you both.

对我来说,例如Google故意让您不要直接从GCS提供服务(带宽原因?Dunno)。因此,根据文档的两种选择是使用Blobstore或图像服务(图片)。

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)

然后,我在服务器上显示此URL-
Main.py:

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

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

FileServer.py:

FileServer.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云存储-App Engine(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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