How to serve google cloud storage image from local server?
Asked Answered
G

1

8

With the latest GAE SDK (1.9.17), I followed all the instructions for serving google cloud storage images using the blobstore and images libraries, yet locally it gives me a 500 error. Deploying the app to the production server, serving the images works fine. However, this is extremely annoying because I need to develop locally, and my project is image intensive.

This works fine in production:

key = blobstore.create_gs_key('/gs/my_bucket/my_folder/my_image.jpg')
url = images.get_serving_url(key)

On production, the serving url looks like:

http://lh6.ggpht.com/ow6Z3PrYyLVdvRDc9cT9I3MB9ug...

Locally, the url looks like:

http://0.0.0.0:8080/_ah/img/encoded_gs_file:Z2lmdF9p...

The App Engine error logs say:

ERROR 2014-12-21 23:12:35,256 blob_download.py:204] Could not find blob with key encoded_gs_file:Z2lmdF9p...

Am I doing something wrong? The docs say serving images locally should work fine after SDK 1.8. If I can't get this to work, my only solution is to keep all production images (many GB's) hosted locally for development.

Gaffrigged answered 21/12, 2014 at 23:15 Comment(1)
Did you solve this? I'm having the same issue...Nilsanilsen
S
3

See this very good repo, which explains how to save file in GCS, either in the development SDK or in production.

Specifically, for your question:

   # image API supported formats
    if file_extension in ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'tiff', 'ico']:
        # High-performance dynamic image serving
        self.serving_url = images.get_serving_url(self.blobkey, secure_url=True)
    elif os.environ['SERVER_SOFTWARE'].startswith('Development'):
        # GCS url: this SDK feature has not been documented yet !!!
        self.serving_url = '/_ah/gcs%s' % self.gcs_filename
    else:
        # GCS url: because of HTTPS we cannot use a cname redirect or use the use_blobstore option
        self.serving_url = 'https://storage.googleapis.com%s' % self.gcs_filename

Thanks to @voscausa.

Stucker answered 12/2, 2015 at 20:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.