Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 如何在谷歌云上提供来自私有bucket的图像/文件_Google App Engine_Flask_Google Cloud Storage - Fatal编程技术网

Google app engine 如何在谷歌云上提供来自私有bucket的图像/文件

Google app engine 如何在谷歌云上提供来自私有bucket的图像/文件,google-app-engine,flask,google-cloud-storage,Google App Engine,Flask,Google Cloud Storage,我一直在琢磨如何从我的appenginebucket(或任何私人bucket)中获取图像,并将其显示在运行GCP appengine的Flask网站上 我正在尝试以下的变体: @app.route('/get_object/<object>') def get_object(object): client = storage.Client() bucket = client.get_bucket('bucket-id') blob = bucket.get_b

我一直在琢磨如何从我的appenginebucket(或任何私人bucket)中获取图像,并将其显示在运行GCP appengine的Flask网站上

我正在尝试以下的变体:

@app.route('/get_object/<object>')
def get_object(object):
    client = storage.Client()
    bucket = client.get_bucket('bucket-id')
    blob = bucket.get_blob(object)

    return blob
@app.route('/get_object/'))
def get_对象(对象):
client=storage.client()
bucket=client.get_bucket('bucket-id'))
blob=bucket.get\u blob(对象)
返回斑点
我的HTML看起来是这样的:

<img src={{ url_for('get_object', object='test.jpg') }}>

在我的appenginedefaultbucket中,我有一张名为
test.jpg
的照片,但似乎没有任何效果。我的存储桶必须是私有的,是否仍有提供私有文件的功能?

我这样做:

My image src使用python函数传递bucket和对象

<img src="{{ url_for('get_file', bucket='testBucket', object='image.png') }}">

下面是函数

@app.route('/get_file/'))
@需要授权
def get_文件(testBucket,对象):
storage\u client=storage.client()
bucket=存储\客户端。获取\ bucket(testBucket)
blob=bucket.blob(对象)
使用tempfile.TemporaryDirectory()作为tmpdirname:
fullpath=os.path.join(tmpdirname,对象)
blob.download_to_filename(完整路径)
从_目录返回发送_(tmpdirname,对象)
这会将App Engine应用程序的本地文件保存在一个临时目录中,一旦函数在返回中存在,该临时目录就会被删除,因此用户会获得该文件,但临时位置不再存在。我想