Google App Engine - 在Google云端存储中使用Blobstore API [英] Google App Engine - Using Blobstore API with Google Cloud Storage

查看:131
本文介绍了Google App Engine - 在Google云端存储中使用Blobstore API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不存储1MB大小的文件,谷歌应用引擎建议我将它们存储在Google云端存储中。应用引擎BlobProperty不合适。



在Google云端存储中使用Blobstore API 建议使用create_upload_url函数的gs_bucket_name参数。



我试过了。

  gcs_upload_url = blobstore.create_upload_url('/ myupload',gs_bucket_name ='bucketname.appspot.com /')

我为POST得到的URL不是 / myupload
它有点像

 < form action =http://myapp.appspot.com/_ah/upload/ XXXXXXXXXXX7NNN-XXXXYYY /method =postenctype =multipart / form-data> 

我更改了/ upload /后的部分,但重点在于,显然错过了创建适当的上传的URL,可以被我的处理程序识别。



使用create_upload_url和gs_bucket_name的正确方法是什么,并且获取处理帖子的正确URL?



很显然,官方文档在这里没有帮助。 create_upload_url 函数是success_path。


处理上传请求的请求处理程序的URL路径,在用表单提交的文件上传后到Blobstore。


成功路径在文件上传到BlobStore或Google云端存储后由App Engine调用。


当用户提交上传网页表单时,如果您使用该上传数据而不是Blobstore,则上传的数据将直接转到Blobstore或Google云端存储。 (Google Cloud Storage需要gs_bucket_name参数。)Blobstore重写传入的请求以除去上载的数据(MIME部分主体)并添加Blobstore密钥(作为MIME部分中的标头),然后将重写的请求传递给应用程序处理程序与为create_upload_url()提供的URL路径关联,作为success_path。


这个函数提供的URL是用来作为动作的的上传表单。您提供的路径类似于上传后处理程序。


I had to store files which had sizes to the north of 1MB and google app engine advised that I should store them in Google Cloud Storage. The app engine BlobProperty was not suitable.

The section Using Blobstore API with Google Cloud Storage advises to use, create_upload_url function's gs_bucket_name parameter.

I tried it.

gcs_upload_url = blobstore.create_upload_url('/myupload', gs_bucket_name='bucketname.appspot.com/')

The resultant URL that I get for the POST is not /myupload, It goes somewhat like

<form action="http://myapp.appspot.com/_ah/upload/XXXXXXXXXXX7NNN-XXXXYYY/" method="post" enctype="multipart/form-data">

I have changed the part after /upload/, but the point is, it clearly misses creating a proper upload URL, which can be recognized by my handler.

What's the correct way to use create_upload_url with gs_bucket_name and also get the correct URL for handing the post?

Clearly the official documentation is not helpful here.

解决方案

The path you passed in create_upload_url function is success_path. See description below.

The URL path of the request handler that will process the upload request, after the file submitted with the form has been uploaded to the Blobstore.

The success_path is called by App Engine after the file has been uploaded into BlobStore or Google Cloud Storage.

When the user submits an upload web form, the uploaded data goes directly to the Blobstore or to Google Cloud Storage if you use that instead of Blobstore. (Google Cloud Storage requires the gs_bucket_name parameter.) The Blobstore rewrites the incoming request to remove the uploaded data (the MIME part body) and add the Blobstore key (as a header in the MIME part), then passes the rewritten request to the application handler associated with the URL path given to create_upload_url() as success_path. The handler at that path can process the rest of the form.

The URL provided by this function is intended to be used as the action of your upload form. The path provided by you is something like post-upload handler.

这篇关于Google App Engine - 在Google云端存储中使用Blobstore API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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