I imagine the process of using the blobstore to store images ends in saving the blob key in the datastore. So in the following code, which is supposed to be in my backend, why do I need a redirect URL since I already have the blob key? Why would I not just save the blob key in my datastore and then return it?
public class Upload extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("myFile");
if (blobKey == null) {
res.sendRedirect("/");
} else {
res.sendRedirect("/serve?blob-key=" + blobKey.getKeyString());
}
}
}
This code is from the tutorial: https://developers.google.com/appengine/docs/java/blobstore/overview#Complete_Sample_App
Because Google store the images on a different service (used by Picassa as well). The goal is to optimize the storage and to provide the developer some tools to manipulate those images easily.
See this reference in the documentation to see what you could do: https://developers.google.com/appengine/docs/java/images/overview
To avoid the redirection, you should use this method to serve images: getServingUrl()
From the documentation:
The getServingUrl() method allows you to generate a stable, dedicated URL for serving web-suitable image thumbnails. You simply store a single copy of your original image in Blobstore, and then request a high-performance per-image URL. This special URL can serve that image resized and/or cropped automatically, and serving from this URL does not incur any CPU or dynamic serving load on your application (though bandwidth is still charged as usual). Images are served with low latency from a highly optimized, cookieless infrastructure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With