5

I am trying to figure out a way to upload an image into Google Cloud Storage using Google App Engine.

I have checked:

Sending images to google cloud storage using google app engine

Upload images/video to google cloud storage using Google App Engine

They all show how to do it using the BlobStore API.

When I checked the BlobStore API:https://cloud.google.com/appengine/docs/python/blobstore/

They have a note to use Google Cloud Storage instead. What's the current status of BlobStore and will it be supported in the future?

I see an example for image upload: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/blobstore/main.py using BlobStore API.

Is there an example for Google Cloud Storage using Google App Engine?

Community
  • 1
  • 1
ssk
  • 9,045
  • 26
  • 96
  • 169
  • 1
    example using signed url : https://github.com/voscausa/appengine-gcs-upload – voscausa Jul 07 '16 at 00:52
  • This may be what you are looking for: https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/app-engine-cloud-storage-sample – ChrisC73 Jul 07 '16 at 01:20

3 Answers3

6

Uploading images through App Engine has three problems:

First, it's very inefficient. You are using your App Engine instance hours to simply pass-through data from a user's browser to Google Cloud Storage.

Second, it's slower (again, because you use an intermediary).

Finally, App Engine does not support streaming and all requests are limited to 32MB.

The best option is to upload files directly to Cloud Storage using one of the upload options.

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Running python code [cloud function python](https://github.com/MartinSahlen/cloud-functions-python) on [cloud function](https://cloud.google.com/functions/). I want to upload an `image` file to the `google cloud storage`. I'm using [PIL](https://pillow.readthedocs.io/en/3.1.x/reference/Image.html) to save image in `.jpg` in buffer. `buffer = BytesIO()` `out.save(buffer,format="PNG")` `out = buffer.getvalue()` Can I pass this `out` in place of 'image' in this [question here](https://stackoverflow.com/questions/49651351/upload-ndarrayimage-in-opencv-on-to-google-cloud-storage-as-a-jpg-or-png)? – Santhosh Apr 05 '18 at 07:26
3

I ended up using https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/app-engine-cloud-storage-sample (The GCS client @ChrisC73 pointed out.

Also, referred to @vocausa's signed_url project: https://github.com/voscausa/appengine-gcs-signed-url

ssk
  • 9,045
  • 26
  • 96
  • 169
1

I upvoted the above answer as you should try to avoid passing data through App Engine if possible. If you really need to upload an image (or any other data) from App Engine to Google Cloud Storage in Python, the answer is as ChrisC73 pointed out to use the GoogleAppEngineCloudStorageClient, as there is no built-in API for Cloud Storage on the Python runtime.

In contrast, the PHP runtime has built-in support for Google Cloud Storage with the standard filesystem functions.

Adam
  • 5,697
  • 1
  • 20
  • 52