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

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

问题描述

在应用程序引擎中,我可以使用我的应用程序的默认存储桶来为诸如pdf之类的云存储文件提供服务:

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

但是,如何在SDK中提供本地云存储文件,而无需使用blob_key?



我写入如下默认存储桶:

  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'



在SDK数据存储中,我有一个Kind: GsFileInfo ,显示: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))


解决方案

UPDATE我发现这个功能可以使用SDK来提供cloudstorage文件:

此功能尚未记录。

  http:// localhost:8080 / _ah / gcs / app_default_bucket /文件名

这表示我们不需要img服务网址来投放非图片下面!!!



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

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

在SDK中,您需要使用blobstore来读取blob并为cloudstorage对象创建服务网址。



我还将代码添加到在SDK和GAE制作中读取,写入和上传cloudstorage blob。



可以找到代码


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>

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)

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

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

Update and workaround: You can get a serving url for NON image files like css, js and 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))

解决方案

UPDATE I found this feature to serve cloudstorage files using the SDK:

This feature has not been documented yet.

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

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

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:

IMPORTANT: the images.get_serving_url() works also for NON images in the SDK!!

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

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

The code can be found here.

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

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