Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getServingUrl() Method using Google Cloud Storage value

how would you create a basic URL for an image using getServingUrl() without using Blobs? All the examples I've seen so far involved blobs, but I need to use Google Cloud Storage value.

Thanks.

like image 386
Leonardo DaVintik Avatar asked Sep 19 '13 21:09

Leonardo DaVintik


People also ask

What is Google Blobstore?

The Blobstore API allows your application to serve data objects, called blobs, that are much larger than the size allowed for objects in the Datastore service. Blobs are useful for serving large files, such as video or image files, and for allowing users to upload large data files.

What is signed URL in GCS?

A signed URL is a URL that provides limited permission and time to make a request. Signed URLs contain authentication information in their query string, allowing users without credentials to perform specific actions on a resource.

What is Gsutil URI?

gsutil is a Python application that lets you access Cloud Storage from the command line. You can use gsutil to do a wide range of bucket and object management tasks, including: Creating and deleting buckets. Uploading, downloading, and deleting objects.


1 Answers

There is a new overload for getServingUrl() with a ServingUrlOptions method argument. And its builder has a withGoogleStorageFileName() method that you can use to create a URL based on the Cloud Storage filename.

GcsFilename gcsFilename = new GcsFilename("bucketName", "objectName");
ImagesService is = ImagesServiceFactory.getImagesService(); 
String filename = String.format("/gs/%s/%s", gcsFilename.getBucketName(), gcsFilename.getObjectName());
String servingUrl = is.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(filename));

Javadocs:

  1. https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ImagesService.html#getServingUrl(com.google.appengine.api.images.ServingUrlOptions)
  2. https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ServingUrlOptions.Builder.html
like image 129
Zsolt Safrany Avatar answered Sep 23 '22 01:09

Zsolt Safrany