How to compress images/video with Google Cloud Storage create_upload_url

9 views
Skip to first unread message

JK140 via StackOverflow

unread,
May 9, 2017, 11:28:05 AM5/9/17
to google-appengin...@googlegroups.com

I have an iOS app in which users upload images directly to Google Cloud Storage. I achieve this by using the function blobstore.create_upload_url in my Python Google App Engine backend, and sending the URL to my app.

However, displaying these images back to the user is taking too long as the images are too large, so I realize I need to compress these images in Google Cloud Storage.

Do you know how this can be achieved programmatically? I know I can execute terminal commands to get compress and re-upload images to Google Cloud Storage but I need to do this programmatically within my app.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/43873861/how-to-compress-images-video-with-google-cloud-storage-create-upload-url

alpeware via StackOverflow

unread,
May 9, 2017, 1:03:05 PM5/9/17
to google-appengin...@googlegroups.com

I'm not entirely sure what type of compression you are looking for, but app engine provides a image service allowing you to resize the images.

From their docs, you can use the image service with the blob store as a source -

The Images service can use a Blobstore value as the source of a transformation. The source image can be as large as the maximum size for a Blobstore value. The Images service still returns the transformed image to the application, so the transformed image must be smaller than 32 megabytes. This is useful for making thumbnail images of large photographs uploaded by users.

Something along these lines -

from google.appengine.api import images

image = Image(blob_key=YOUR_BLOB_KEY)
image.resize(width=YOUR_WIDTH, height=YOUR_HEIGHT)
compressed_image = image.execute_transforms(output_encoding=images.JPEG)

Here's an overview of the API and list api reference -

https://cloud.google.com/appengine/docs/standard/python/images/ https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.images



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/43873861/how-to-compress-images-video-with-google-cloud-storage-create-upload-url/43875767#43875767
Reply all
Reply to author
Forward
0 new messages