title: Google App Engine - Updating a blobstore via byte array using simulated POST
body: <p>I'm getting the following exception when I try to simulate a post request to upload to the app engine blobstore using Java:</p>
  
  <blockquote>
  <pre><code>WARNING: /_ah/login
  java.lang.NullPointerException
    at com.google.appengine.api.users.dev.LoginCookieUtils.encodeEmailAsUserId(LoginCookieUtils.java:89)
    at com.google.appengine.api.users.dev.LoginCookieUtils.createCookie(LoginCookieUtils.java:41)
    at com.google.appengine.api.users.dev.LocalLoginServlet.doPost(LocalLoginServlet.java:90)
  </code></pre>
  </blockquote>
  
  <p>Here's is the code that is doing the POST request:</p>
  
  <pre><code>byte[] htmlData = // ...I already have the byte array I want to store/update)
  
      BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
              String uploadURL = blobstoreService.createUploadUrl("/upload");
  
                           //add host if in dev mode
               if(uploadURL.indexOf("http") == -1)
               {
                   uploadURL = "http://localhost:8888" + uploadURL;
               }
               URL url = new URL(uploadURL);
               // create a boundary string
               String boundary = MultiPartFormOutputStream.createBoundary();
               URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
               urlConn.setReadTimeout(15000);
               urlConn.setRequestProperty("Accept", "*/*");
               urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary));
               // set some other request headers...
               urlConn.setRequestProperty("Connection", "Keep-Alive");
               urlConn.setRequestProperty("Cache-Control", "no-cache");
               // no need to connect because getOutputStream() does it
               MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
  out.writeField("param", "value")
  out.writeFile("myFile", "multipart/form-data", "content.html", htmlData);
           out.close();
  </code></pre>
  
  <p>Then in upload.java</p>
  
  <pre><code>public class Upload extends HttpServlet 
  {
  
      private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
  
      public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 
      {
          UserService userService = UserServiceFactory.getUserService();
          User user = userService.getCurrentUser();
          Map&lt;String, BlobKey&gt; blobs = blobstoreService.getUploadedBlobs(req);
          BlobKey blobKey = blobs.get("myFile");
          String value = req.getParameter("param");
          Topic t = pm.getObjectById(Topic.class, key);
          t.setParam("value");
      try
      {
          pm.makePersistent(t);
      }
  </code></pre>
  
  <p>....</p>
  
  <p>Why am I getting an exception for encodeEmailAsUserId?</p>
  
  <p>P.S. The writeFields persist and update just fine in the Datastore, but I still get this exception.</p>