Replacing BlobStore Upload Handler with GCS

﹥>﹥吖頭↗ 提交于 2019-12-24 07:56:34

问题


I'm looking at replacing our usage of the Blobstore API with GCS, per the recommendation in the Blobstore docs.

As far as I can tell, the right way to allow a user to upload a files seems to be to pass them a signed URL where they can upload their data.

The piece I'm missing is that the Blobstore API has an UploadHandler, which allows you to perform some actions when a file has been uploaded (e.g. store metadata in a database), and even return a response to the user's upload request.

Is there something similar for GCS? What is the recommended approach there? Relying on the user to notify the app that it has finished uploading a file seems prone to errors.


回答1:


The Object Change Notification represents the GCS concept that comes closest to the blobstore API upload handler. At the end of that doc there is a GAE app usage example.

However controlling the Object Change Notifications registrations is done via manual gsutil invocations, so it may be a bit tricky to use.

BTW, I think the actual storage, not the API itself is being deprecated. Or at least that's my interpretation of the Blobstore Python API Overview note:

Note: You should consider using Google Cloud Storage rather than Blobstore for storing blob data.

Personally I'm sticking with the blobstore API for now, at least until an actual API deprecation date is published and/or active deprecation warnings start flowing - other options may become available by then.




回答2:


The uploading process is not different at all to BlobStore, you just need to create the upload url with the cloud storage bucket (gs_bucket_name) named

google.appengine.ext.blobstore.blobstore.create_upload_url(success_path, max_bytes_per_blob=None, max_bytes_total=None, rpc=None, gs_bucket_name=None)



回答3:


In the meantime, I stumbled upon an answer to a similar question: Provide a callback URL in Google Cloud Storage signed URL

The answer seems to be to use the (discouraged) form POST method, and add a succes_action_redirect header. Too bad this isn't available for PUT. Not 100% what I wanted though, so I guess i'm stuck with Blobstore.



来源:https://stackoverflow.com/questions/42002013/replacing-blobstore-upload-handler-with-gcs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!