GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Get Serving URL for images stored in Storage (Similar to App Engine Image Class) · Issue #1295 · googleapis/google-cloud-python

Get Serving URL for images stored in Storage (Similar to App Engine Image Class) #1295

New issue
Copy link
New issue
Copy link
Closed
Closed
Get Serving URL for images stored in Storage (Similar to App Engine Image Class)#1295
Copy link
Assignees
dhermes
Labels
api: storageIssues related to the Cloud Storage API.

Description

@saxenanurag
saxenanurag
opened on Dec 16, 2015
Issue body actions

Would it be possible to get something similar to get_serving_url in app engine (https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.images#google.appengine.api.images.get_serving_url) using this library as well?
Thanks.

Reacted by Michael DeRazon, uvtzxpm, Jason Cartwright, Adam Alton, Phil Rukin, Olzhas Alexandrov, Guido Bouman, Stian Lind Petlund, castaneai and oon arfiandwi

Activity

Next
  1. dhermes commented on Dec 17, 2015

    @dhermes
    dhermes
    on Dec 17, 2015
    Contributor
    More actions

    Thanks @saxenanurag, you can already do this to some degree:

    from gcloud import storage
    client = storage.Client()  # Implicit environ set-up
    bucket = client.bucket('my-bucket')
    blob = bucket.blob('my-blob')
    url_lifetime = 3600  # Seconds in an hour
    serving_url = blob.generate_signed_url(url_lifetime)

    I'm going to close this out, but if you think this doesn't meet your needs, I'm happy to re-open and discuss.

    Reacted by Ilham Bintang, Cool Store, Zhangao Lu and Joseph Makram
    Reacted by Adam Alton
  2. dhermes
    closed this as completedon Dec 17, 2015
  3. saxenanurag commented on Dec 17, 2015

    @saxenanurag
    saxenanurag
    on Dec 17, 2015
    Author
    More actions

    Does this mean that the link expires in 3600 seconds? Thanks.

  4. dhermes commented on Dec 17, 2015

    @dhermes
    dhermes
    on Dec 17, 2015
    Contributor
    More actions

    Yes it does. Your other alternative is to use the publicRead ACL: https://cloud.google.com/storage/docs/access-control

    and then there is a Blob.public_url property to use.

  5. saxenanurag commented on Dec 17, 2015

    @saxenanurag
    saxenanurag
    on Dec 17, 2015
    Author
    More actions

    That is not what get_serving url does. Here is the quote from the app engine documentation:

    Using get_serving_url() allows you to dynamically resize and crop images, so you don't need to store
    different image sizes on the server. This method returns a URL that serves the image, and transformations to the image are encoded in this URL.

    https://cloud.google.com/appengine/docs/python/images/

    I am working on a project that is currently on App Engine. We are moving it to Compute Engine but are still using Cloud Storage for static file storage. get_serving_url helped in serving images in multiple sizes, without giving away the folder structure of the storage.

  6. dhermes commented on Dec 17, 2015

    @dhermes
    dhermes
    on Dec 17, 2015
    Contributor
    More actions

    Actually doing the resizing is a feature of App Engine that isn't present in the Cloud Storage API. This library simply offers the API methods (and tries to make them helpful and useful). Resizing images goes outside that scope, sorry.

  7. dhermes commented on Dec 17, 2015

    @dhermes
    dhermes
    on Dec 17, 2015
    Contributor
    More actions

    @jgeewax Do you know if there is any Cloud API (outside of GAE) that can do resizing and serving on the fly?

  8. dhermes
    added
    api: storageIssues related to the Cloud Storage API.
    on Dec 31, 2015
  9. robin-anil commented on Jun 18, 2016

    @robin-anil
    robin-anil
    on Jun 18, 2016
    More actions

    +1 would love to see get_serving_url functionality come to google cloud storage api.

    Reacted by Jesse Hattabaugh, Olzhas Alexandrov, Cyril Quinton, DNRN, sāmīr, mdornseif and Callum Smith
  10. jgeewax commented on Jun 27, 2016

    @jgeewax
    jgeewax
    on Jun 27, 2016
    Contributor
    More actions

    So... I'm just gonna leave this here.... https://gist.github.com/carlo/5379498

    Reacted by Cristyan Sepúlveda V and Jorge Lison
    Reacted by Thomas Schultz, Robin Anil and sqwk
    Reacted by Mike Brew
  11. robin-anil commented on Jun 27, 2016

    @robin-anil
    robin-anil
    on Jun 27, 2016
    More actions

    Thats a great tip @jgeewax However we don't want this to be taken down from under us, we are looking for a serious SLA on this one. We have had issues with various beta apis breaking and causing production issues. I am a Xoogler and remembers how bad Google used to be at keeping API. So forgive my caution.

    I would really like Google to provide a public API for this and hope this comes with standard Google cloud storage api, since we have the originals in cloudstorage.

  12. theacodes commented on Jun 27, 2016

    @theacodes
    theacodes
    on Jun 27, 2016
    Contributor
    More actions

    @r-tock if you need something production-ready, I would highly recommend that you generate all of the sizes you need ahead-of-time.

    You can even write a small App Engine application that listens for object uploads and then generates the resized versions using PIL and uploads them.

    Reacted by Robert Felker
  13. jgeewax commented on Jun 27, 2016

    @jgeewax
    jgeewax
    on Jun 27, 2016
    Contributor
    More actions

    Yea, that's completely unofficial.

    AFAIK, we don't have an API for dealing with images that way. The best route to go is probably a mini GAE app as @jonparrott said.

    Reacted by Cool Store
  14. robin-anil commented on Jun 27, 2016

    @robin-anil
    robin-anil
    on Jun 27, 2016
    More actions

    @jonparrott @jgeewax I am doing exactly that, I have a mini App engine app which return the serving url from any of our internal buckets.

    Given that this Api does not work on the new Managed container runtime, I am worried about the future of that API as well. That is why I would like it to be ported to either the new Managed container runtime or directly in the Google storage api.

  15. theacodes commented on Jun 27, 2016

    @theacodes
    theacodes
    on Jun 27, 2016
    Contributor
    More actions

    @r-tock I do not know any details on the future of the Images API but in the event of any deprecation we have a 1-year deprecation policy as stated in our terms of service.

    In terms of APIs available in the Flexible runtime - please keep in mind that Flexible is in beta and features may be added or removed. In general we're trying to make most APIs available from anywhere like we have done with Cloud Datastore.

    As I mentioned, if you want to truly remove dependence on that API then I'd recommend having your small App Engine app generate the size ahead-of-time instead of producing a serving URL.

  16. 9 remaining items

  17. savraj commented on Oct 15, 2017

    @savraj
    savraj
    on Oct 15, 2017
    More actions

    Guys, this works right now -- the get_serving_url functionality works for me on the dev server and will try on production soon. Here's how you do it -- you call get_serving_url like this:

    get_serving_url(None, filename="/gs/mybucket/myfile.jpg")

    Reacted by mdornseif
  18. reco commented on Jan 26, 2018

    @reco
    reco
    on Jan 26, 2018
    More actions

    @savraj can you do resizing on the fly by adding =s200 to your serving url?

  19. savraj commented on Jan 26, 2018

    @savraj
    savraj
    on Jan 26, 2018
    More actions

    yes I believe so, though I haven't thought about this in years :)

    Reacted by Nell David Soledad
  20. ShaMan123 commented on Apr 13, 2018

    @ShaMan123
    ShaMan123
    on Apr 13, 2018
    More actions

    @savraj could you provide a git repo with code? I'm having a hard time trying to get this work

  21. ShaMan123 commented on Apr 13, 2018

    @ShaMan123
    ShaMan123
    on Apr 13, 2018
    More actions

    +1

  22. asciimike commented on Apr 13, 2018

    @asciimike
    asciimike
    on Apr 13, 2018
    More actions

    @ShaMan123, I have a minimal example of Python + Image Serving below:

    # main.py
    # Generates a GAE Images API serving URL from a file in GCS
    # Change <your_bucket_name>
    from google.appengine.api import images
    from google.appengine.ext import blobstore
    import webapp2
    class MainPage(webapp2.RequestHandler):
        def get(self):
            file = self.request.get('file')
            gs = "/gs/{0}/{1}".format('<your_bucket_name>', file)
            blob_key = blobstore.create_gs_key(gs)
            url = images.get_serving_url(blob_key, size=150, crop=True, secure_url=True)
            self.response.write(url)
    app = webapp2.WSGIApplication([
        ('/', MainPage),
    ], debug=True)
     
    # Get a serving URL using your app (note that the file must already be in the GCS bucket, you can simply use the Cloud Console to do this)
    $ curl "https://<your-app-name>.appspot.com/?file=<some_file_name.jpg>"
    > https://lh3.googleusercontent.com/<some_long_string>=s150-c
    

    That said, given that Imgix now supports GCS buckets as object sources, I'd strongly recommend taking a look at it.

    Reacted by Richard Hazelden
  23. ShaMan123 commented on Apr 27, 2018

    @ShaMan123
    ShaMan123
    on Apr 27, 2018 via email
    More actions
    thanks! didn't work for me but I found a workaround
    …
    On 13 April 2018 at 18:58, Michael McDonald ***@***.***> wrote: @ShaMan123 <https://github.com/ShaMan123>, I have a minimal example of Python + Image Serving below: # main.py # Generates a GAE Images API serving URL from a file in GCS # Change <your_bucket_name> from google.appengine.api import images from google.appengine.ext import blobstore import webapp2 class MainPage(webapp2.RequestHandler): def get(self): file = self.request.get('file') gs = "/gs/{0}/{1}".format('<your_bucket_name>', file) blob_key = blobstore.create_gs_key(gs) url = images.get_serving_url(blob_key, size=150, crop=True, secure_url=True) self.response.write(url) app = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True) # Get a serving URL using your app (note that the file must already be in the GCS bucket, you can simply use the Cloud Console to do this) $ curl "https://<your-app-name>.appspot.com/?file=<some_file_name.jpg>" > https://lh3.googleusercontent.com/<some_long_string>=s150-c — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1295 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AgwLceuhdkP6Lo15UKPm5Qrm3FTRbMZvks5toMs2gaJpZM4G21Kj> .
  24. hamx0r commented on Jul 24, 2018

    @hamx0r
    hamx0r
    on Jul 24, 2018
    More actions

    One can actually set the blobkey arg to None and then use the filename kwarg to your file path prepended by /gs like this:
    images.get_serving_url(None, filename='/gs{}'.format(filename))

    filename would be like /mybucket/some/path/to/photo.jpg

    In other words, there's no need to use the blobstore.create_gs_key() function as an intermediate step.

  25. JustinBeckwith
    assigned
    dhermes
    on Feb 1, 2021
  26. sbudhram commented on Mar 26, 2021

    @sbudhram
    sbudhram
    on Mar 26, 2021
    More actions

    @ShaMan123 What was your workaround for this issue? I can't get this to work either.

  27. ShaMan123 commented on Mar 28, 2021

    @ShaMan123
    ShaMan123
    on Mar 28, 2021
    More actions

    @sbudhram Sorry I don't remember 🤔 and I think this method has been deprecated.
    But there's getSignedUrl exposed in @google-cloud/storage.
    Maybe it'll help.
    Take a look:
    https://cloud.google.com/storage/docs/access-control/signed-urls
    https://googleapis.dev/nodejs/storage/latest/Bucket.html#getSignedUrl
    https://cloud.google.com/storage/docs/access-control/signing-urls-manually

  28. parthea
    added a commit that references this issue on Sep 22, 2023

    BigQuery: Add Data Transfer Service quickstart. [(#1295)](GoogleCloud…

    0a98581
  29. parthea
    added 2 commits that reference this issue on Nov 24, 2025

    chore: update getting-started doc (#1295)

    485a0ec

    chore(main): release 2.18.1 (#1295)

    69eb2fd
  30. parthea
    added a commit that references this issue on Mar 6, 2026

    feat: Add More Specific Type Annotations for Row Dictionaries (#1295)

    a214475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.