diff --git a/appengine-java8/images/src/main/java/com/example/appengine/images/ImagesServlet.java b/appengine-java8/images/src/main/java/com/example/appengine/images/ImagesServlet.java index 114254a9c92..d8ae82035a5 100644 --- a/appengine-java8/images/src/main/java/com/example/appengine/images/ImagesServlet.java +++ b/appengine-java8/images/src/main/java/com/example/appengine/images/ImagesServlet.java @@ -22,6 +22,7 @@ import com.google.appengine.api.images.Image; import com.google.appengine.api.images.ImagesService; import com.google.appengine.api.images.ImagesServiceFactory; +import com.google.appengine.api.images.ServingUrlOptions; import com.google.appengine.api.images.Transform; import com.google.appengine.tools.cloudstorage.GcsFileOptions; import com.google.appengine.tools.cloudstorage.GcsFilename; @@ -108,6 +109,16 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc ByteBuffer.wrap(rotatedImage.getImageData())); //[END rotate] + // [START servingUrl] + // Create a fixed dedicated URL that points to the GCS hosted file + ServingUrlOptions options = ServingUrlOptions.Builder + .withGoogleStorageFileName("/gs/" + bucket + "/image.jpeg") + .imageSize(150) + .crop(true) + .secureUrl(true); + String url = imagesService.getServingUrl(options); + // [END servingUrl] + // Output some simple HTML to display the images we wrote to Cloud Storage // in the browser. PrintWriter out = resp.getWriter(); @@ -118,6 +129,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc + "/resizedImage.jpeg' alt='AppEngine logo resized' />"); out.println("AppEngine logo rotated"); + out.println("Hosted logo"); out.println("\n"); } }