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);
}
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