Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve google cloud storage image from local server?

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.

like image 615
seibelj Avatar asked Dec 21 '14 23:12

seibelj


People also ask

Can I upload files to Google Cloud Storage from URL?

Cloud Storage provides the Signed URL feature to let individual end users perform specific actions. Signed URL makes it possible to generate temporary credentials valid only for a specific end user to securely upload a file. The Google Cloud official client library makes it easy to generate a Signed URL.


1 Answers

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.

like image 85
Eliel Haouzi Avatar answered Sep 28 '22 10:09

Eliel Haouzi