0
votes

https://cloud.google.com/appengine/docs/standard/python/blobstore/ describes exactly how to do this using AppEngine and Blobstore. And apparently the same API can be used to upload to Cloud Storage. I'm not able to use AppEngine for other reasons. I'm trying to use Cloud Run. And for anyone not using AppEngine, the Cloud Storage docs don't show any clear way to upload from a browser.

I want something like blobstore.create_upload_url, but that API is only provided via the appengine libraries in the AppEngine runtime and are not available in other environments.

Cloud Storage has create_resumable_upload_session, which creates an upload URL. But if you stick that in a browser form - the way you do with create_upload_url - it doesn't issue a redirect back to the app after upload completion.

1
Typically people use Firebase SDKs to upload directly to Cloud Storage from client apps. - Doug Stevenson
I'm open to alternative approaches. Can you elaborate? - philo

1 Answers

1
votes

Cloud Run allows you to use any of the GCP services listed here including Cloud Storage APIs and client libraries.

The Cloud Storage XML API allows for uploading objects via HTML forms using POST Object. To implement a redirect after a successful upload you can specify this in a policy document which you include in the form. The documentation has instructions and an example of the necessary encoding and signature required for the policy document.

There's also the option for resumable uploads using the XML API. The docs have steps for uploads of known size, unknown size and cancelling uploads.