Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding serving url sample #890

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always think of this as gs:// - please check this. Otherwise LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - this is blob store. It's ok.

.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