将文件直接上传到Google Cloud Storage for GAE应用程序 [英] Uploading files directly to Google Cloud Storage for GAE app

查看:536
本文介绍了将文件直接上传到Google Cloud Storage for GAE应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Blobstore中,我们正在从Blobstore切换到Google云端存储,以便在项目中进行图片上传(因为Google调用了Blobstore已取代多部分表单将直接提交(上传)到Blobstore,然后它将重写请求并重定向到GAE应用程序以处理 BlobKey (s)。这意味着GAE应用的负载很小。



是否有一种方法可以实现与Google云端存储(GCS)类似的工作流?



给出的示例读取和写入Google云端存储涉及GAE代码,用于处理上传,读取数据并将其保存在GCS中。



类似地,上传的图像文件:好像一个处理程序必须在GAE代码中实现,才能从GCS读取并返回图像数据。



没有办法简单地生成一个在GCS中的资源的URL(AFAIK AWS S3支持这个),并让它从那里提供? 您可以保留使用blobstore API但实际存储在GCS中,意味着相同的上传行为,并且可能对您的应用程序进行的最低限度的更改。 在Google云端存储(Python)中使用Blobstore API


您可以使用Blobstore API将Blob存储在Cloud Storage中,而不是将它们存储在Blobstore中
。您需要按照 Google云端存储中介绍的
设置存储分区>文档,并在和文件名.ext.blobstore.blobstore.create_upload_urlrel =nofollow> blobstore.blobstore.create_upload_url
gs_bucket_name 参数。在上传处理程序中,您需要处理返回的

一个完整的示例应用程序也在那里呈现。



更新:糟糕,上述答案适用到Python环境,Java如下:

来自在Google Cloud Storage(Java)中使用Blobstore API Blobstore API将Blob存储在Cloud Storage中,而不是
将它们存储在Blobstore中。您需要按照 Google云端存储中的
所述设置存储桶>文档,并在 BlobstoreService中指定存储桶
和文件名
createUploadUrl ,指定
中的存储桶名称UploadOptions参数。在您的上传
处理程序中,您需要处理返回的 FileInfo 元数据和
明确存储了Google Cloud Storage文件名,以便稍后检索
blob。


没有完整的Java示例应用程序。

I am looking at switching from Blobstore to Google Cloud Storage for things like image uploads in a project (since Google calls Blobstore "superseded").

In Blobstore, the multipart form would be submitted (uploaded) directly to the Blobstore, which would then rewrite the request and redirect to the GAE app for handling the BlobKey(s). This meant very little load on the GAE app.

Is there a way to implement a similar workflow with Google Cloud Storage (GCS)?

The example given at Reading and Writing to Google Cloud Storage involves GAE code handling the upload, reading the data and saving it in GCS.

Similarly for serving the (for example) uploaded image file: seems like a handler has to be implemented in one's GAE code to read from GCS and return the image data.

Isn't there a way to simply generate a URL for a resource in GCS (AFAIK AWS S3 supports this) and let it be served from there?

解决方案

You can keep using the blobstore API but with actual storage in GCS, meaning same upload behaviour and probably minimal changes to your app.

From Using the Blobstore API with Google Cloud Storage (Python):

You can use the Blobstore API to store blobs in Cloud Storage instead of storing them in Blobstore. You need to set up a bucket as described in the Google Cloud Storage documentation and specify the bucket and filename in the blobstore.blobstore.create_upload_url gs_bucket_name parameter. In your upload handler, you need to process the returned FileInfo metadata and explicitly store the Google Cloud Storage filename needed to retrieve the blob later.

A complete example app is presented there as well.

Update: Oops, the above answer applies to the Python environment, the Java one follows:

From Using the Blobstore API with Google Cloud Storage (Java):

You can use the Blobstore API to store blobs in Cloud Storage instead of storing them in Blobstore. You need to set up a bucket as described in the Google Cloud Storage documentation and specify the bucket and filename in the BlobstoreService createUploadUrl, specify the bucket name in the UploadOptions parameter. In your upload handler, you need to process the returned FileInfo metadata and explicitly store the Google Cloud Storage filename needed to retrieve the blob later.

There is no complete sample app for Java, tho.

这篇关于将文件直接上传到Google Cloud Storage for GAE应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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