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) #1295DescriptionReacted by Michael DeRazon, uvtzxpm, Jason Cartwright, Adam Alton, Phil Rukin, Olzhas Alexandrov, Guido Bouman, Stian Lind Petlund, castaneai and oon arfiandwi Activitydhermes commented on Dec 17, 2015 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 saxenanurag commented on Dec 17, 2015 Does this mean that the link expires in 3600 seconds? Thanks. dhermes commented on Dec 17, 2015 saxenanurag commented on Dec 17, 2015 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. dhermes commented on Dec 17, 2015 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. dhermes commented on Dec 17, 2015 @jgeewax Do you know if there is any Cloud API (outside of GAE) that can do resizing and serving on the fly? robin-anil commented on Jun 18, 2016 +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 jgeewax commented on Jun 27, 2016 Reacted by Cristyan Sepúlveda V and Jorge Lison Reacted by Thomas Schultz, Robin Anil and sqwk Reacted by Mike Brew robin-anil commented on Jun 27, 2016 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. theacodes commented on Jun 27, 2016 @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. jgeewax commented on Jun 27, 2016 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. robin-anil commented on Jun 27, 2016 @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. theacodes commented on Jun 27, 2016 @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. savraj commented on Oct 15, 2017 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")
reco commented on Jan 26, 2018 @savraj can you do resizing on the fly by adding =s200 to your serving url? savraj commented on Jan 26, 2018 yes I believe so, though I haven't thought about this in years :) Reacted by Nell David Soledad ShaMan123 commented on Apr 13, 2018 @savraj could you provide a git repo with code? I'm having a hard time trying to get this work ShaMan123 commented on Apr 13, 2018 asciimike commented on Apr 13, 2018 @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 ShaMan123 commented on Apr 27, 2018 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>
.
hamx0r commented on Jul 24, 2018 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. sbudhram commented on Mar 26, 2021 @ShaMan123 What was your workaround for this issue? I can't get this to work either. ShaMan123 commented on Mar 28, 2021
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|