Google App Engine - Using Blobstore API with Googl

2019-02-28 15:50发布

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.

2条回答
霸刀☆藐视天下
2楼-- · 2019-02-28 16:30

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.

查看更多
聊天终结者
3楼-- · 2019-02-28 16:43

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.

查看更多
登录 后发表回答