Search code examples
javagoogle-app-engineblobstoredatastore

App Engine (Java) Blobstore: no BlobInfo after successfully storing blob


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:

  • If I remove the BlobInfo code, the servlet returns the resource as it should (but without a filename)
  • For brevity, I removed exception and parameter handling

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

Solution

  • 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