如何使用应用引擎 SDK 提供云存储文件 [英] How to serve cloudstorage files using app engine SDK

查看:28
本文介绍了如何使用应用引擎 SDK 提供云存储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用引擎中,我可以使用应用程序的默认存储桶提供 pdf 等云存储文件:

In app engine I can serve cloudstorage files like a pdf using the default bucket of my application:

http://storage.googleapis.com/<appid>.appspot.com/<file_name>

但是如何在不使用 blob_key 的情况下在 SDK 中提供本地云存储文件?

But how can I serve local cloudstorage files in the SDK, without making use of a blob_key?

我像这样写入默认存储桶:

I write to the default bucket like this:

gcs_file_name = '/%s/%s' % (app_identity.get_default_gcs_bucket_name(), file_name)
with gcs.open(gcs_file_name, 'w') as f:
    f.write(data)

SDK 中默认存储桶的名称 = 'app_default_bucket'

The name of the default bucket in the SDK = 'app_default_bucket'

在 SDK 数据存储中,我有一个 Kind:GsFileInfo 显示:文件名:/app_default_bucket/example.pdf

In the SDK datastore I have a Kind: GsFileInfo showing: filename: /app_default_bucket/example.pdf

更新和解决方法:您可以获得非图像文件(如 css、js 和 pdf)的服务网址.

gs_file = '/gs/%s/%s/%s' % (app_identity.get_default_gcs_bucket_name(), folder, filename)
serving_url = images.get_serving_url(blobstore.create_gs_key(gs_file))

推荐答案

更新 我发现这个功能可以使用 SDK 提供云存储文件:

尚未记录此功能.

http://localhost:8080/_ah/gcs/app_default_bucket/filename

这意味着我们不需要 img 服务 url 来提供非图像,如下所示!!!

This meands we do not need the img serving url to serve NON images as shown below !!!

要在 default_bucket 中为图像、css、js 和 pdf 等云存储文件创建 e 服务 url,我使用此代码进行测试(SDK)和 GAE 生产:

To create e serving url for cloudstorage files like images, css, js and pdf's in the default_bucket, I use this code for testing(SDK) and GAE production:

重要提示:images.get_serving_url() 也适用于 SDK 中的非图像!!

在 SDK 中,您需要 blobstore 来读取 blob 并为云存储对象创建服务 URL.

In the SDK you stll need the blobstore to read a blob and create a serving url for a cloudstorage object.

我还在 SDK 和 GAE 产品中添加了用于读取、写入和上传云存储 blob 的代码.

I also added the code to read, write and upload cloudstorage blobs in the SDK and GAE production.

可以在此处找到代码.

这篇关于如何使用应用引擎 SDK 提供云存储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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