Reputation: 113
From the documentation of the App Engine Blobstore, there should be a BlobInfo entry in the DataStore for each entry in the BlobStore. Then why is my blobInfo null in the code below?
Note:
I would be very grateful for your help.
public class GetResourceServlet extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
private BlobInfoFactory infoFactory = new BlobInfoFactory();
public void doGet ( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String blobKeyStr = request.getParameter("blob-key");
BlobKey blobKey = new BlobKey(blobKeyStr);
BlobInfo info = infoFactory.loadBlobInfo(blobKey); // returns null !?
String fname = info.getFilename();
response.addHeader("content-disposition", "attachment; filename=" + fname);
blobstoreService.serve(blobKey, response);
}
Upvotes: 3
Views: 1520
Reputation: 113
Finally, I found the problem. The key string (blobKeyStr) contained a newline character at the end. The nasty thing is that you don't notice it in logging. Adding a blobKeyStr = blobKeyStr.trim()
solved the problem
Upvotes: 1
Reputation: 8816
Do the following first:
ensure that the blob is present in the local data store by visiting 'http://local host:8080/_ah/admin' and then data store viewer. You should see new entries Hcreated for your blobs. Note down the key values.
make sure that you are using the correct blob key in your request.
You mentione that you have removed exception handling code from above due to brevity. Do you get any exceptions while ying to retrieve the blob that supposedly does not exist?
Upvotes: 0