简体   繁体   English

Google App Engine-将Blobstore API与Google Cloud Storage结合使用

[英]Google App Engine - Using Blobstore API with Google Cloud Storage

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. 我必须存储大小在1MB以北的文件,并且Google App Engine建议我将它们存储在Google Cloud Storage中。 The app engine BlobProperty was not suitable. 应用引擎BlobProperty不适合。

The section Using Blobstore API with Google Cloud Storage advises to use, create_upload_url function's gs_bucket_name parameter. 建议将Blobstore API与Google Cloud Storage结合使用,建议使用create_upload_url函数的gs_bucket_name参数。

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 我为POST获得的结果URL不是/myupload ,它有点像

<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. 我已经更改了/ upload /之后的部分,但要点是,它显然错过了创建正确的上传URL的过程,我的处理程序可以识别该URL。

What's the correct way to use create_upload_url with gs_bucket_name and also get the correct URL for handing the post? 将create_upload_url与gs_bucket_name结合使用并获得用于处理帖子的正确URL的正确方法是什么?

Clearly the official documentation is not helpful here. 显然,官方文档在这里没有帮助。

The path you passed in create_upload_url function is success_path. 您在create_upload_url函数中传递的路径是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. 在将与表单一起提交的文件上载到Blobstore之后,将处理上载请求的请求处理程序的URL路径。

The success_path is called by App Engine after the file has been uploaded into BlobStore or Google Cloud Storage. 将文件上传到BlobStore或Google Cloud Storage后,App Engine会调用success_path。

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. 当用户提交上传Web表单时,如果您使用上传的数据而不是Blobstore,则上传的数据将直接发送到Blobstore或Google Cloud Storage。 (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. (Google Cloud Storage需要gs_bucket_name参数。)Blobstore重写传入请求以删除上载的数据(MIME部分主体)并添加Blobstore密钥(作为MIME部分中的标头),然后将重写的请求传递给应用程序与指定给create_upload_url()作为成功路径的URL路径关联的处理程序。 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. 此功能提供的URL旨在用作您上载表单的操作。 The path provided by you is something like post-upload handler. 您提供的路径类似于上载后处理程序。

That is the correct way. 那是正确的方法。 The upload URL is handled by AppEngine itself: it will accept the file upload, then call your own handler directly. 上传网址由AppEngine本身处理:它将接受文件上传,然后直接调用您自己的处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM