如何在App Engine Python上创建Google Cloud Storage签名的网址 [英] How to Create Google Cloud Storage Signed Urls on App Engine Python

查看:92
本文介绍了如何在App Engine Python上创建Google Cloud Storage签名的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何使用Python在Google App Engine上实现Google Cloud Storage Signed Urls的简单示例.请编写分步指南. :)

I couldn't find a simple example on how to implement Google Cloud Storage Signed Urls on Google App Engine with Python. Please write a step by step guide. :)

推荐答案

其他解决方案也可以,但是使用

The other solutions work but there is a simpler way using generate_signed_url. This method does the same thing as @voscausa's answer but is less tedious and has custom exceptions and support for other environments.

def sign_url(obj, expires_after_seconds=60):

    client = storage.Client()
    default_bucket = '%s.appspot.com' % app_identity.get_application_id()
    bucket = client.get_bucket(default_bucket)
    blob = storage.Blob(obj, bucket)

    expiration_time = int(time.time() + expires_after_seconds)

    url = blob.generate_signed_url(expiration_time)

    return url

vascausa关于本地开发服务器测试的看法

What vascausa said regarding local development server testing

但是,如果您使用SDK测试应用程序,则必须使用:

But if you use the SDK to test the app, you have to use:

-appidentity_email_address

--appidentity_email_address

-appidentity_private_key_path

--appidentity_private_key_path

因为创建签名的URL不属于GCS客户端.

because creating a signed url is not part of the GCS client.

仍然成立.

这篇关于如何在App Engine Python上创建Google Cloud Storage签名的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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