Skip to content

Commit 0ab44c6

Browse files
jabubakelesv
authored andcommitted
adding serving url sample (#890)
1 parent b14e6c9 commit 0ab44c6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

appengine-java8/images/src/main/java/com/example/appengine/images/ImagesServlet.java

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.appengine.api.images.Image;
2323
import com.google.appengine.api.images.ImagesService;
2424
import com.google.appengine.api.images.ImagesServiceFactory;
25+
import com.google.appengine.api.images.ServingUrlOptions;
2526
import com.google.appengine.api.images.Transform;
2627
import com.google.appengine.tools.cloudstorage.GcsFileOptions;
2728
import com.google.appengine.tools.cloudstorage.GcsFilename;
@@ -108,6 +109,16 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
108109
ByteBuffer.wrap(rotatedImage.getImageData()));
109110
//[END rotate]
110111

112+
// [START servingUrl]
113+
// Create a fixed dedicated URL that points to the GCS hosted file
114+
ServingUrlOptions options = ServingUrlOptions.Builder
115+
.withGoogleStorageFileName("/gs/" + bucket + "/image.jpeg")
116+
.imageSize(150)
117+
.crop(true)
118+
.secureUrl(true);
119+
String url = imagesService.getServingUrl(options);
120+
// [END servingUrl]
121+
111122
// Output some simple HTML to display the images we wrote to Cloud Storage
112123
// in the browser.
113124
PrintWriter out = resp.getWriter();
@@ -118,6 +129,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
118129
+ "/resizedImage.jpeg' alt='AppEngine logo resized' />");
119130
out.println("<img src='//storage.cloud.google.com/" + bucket
120131
+ "/rotatedImage.jpeg' alt='AppEngine logo rotated' />");
132+
out.println("<img src='" + url + "' alt='Hosted logo' />");
121133
out.println("</body></html>\n");
122134
}
123135
}

0 commit comments

Comments
 (0)