Skip to content

Commit

Permalink
adding serving url sample (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
jabubake authored and lesv committed Oct 19, 2017
1 parent b14e6c9 commit 0ab44c6
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -118,6 +129,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
+ "/resizedImage.jpeg' alt='AppEngine logo resized' />");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/rotatedImage.jpeg' alt='AppEngine logo rotated' />");
out.println("<img src='" + url + "' alt='Hosted logo' />");
out.println("</body></html>\n");
}
}
Expand Down

0 comments on commit 0ab44c6

Please sign in to comment.