title: Uploading Image To Google App Engine Blobstore - Java
body: <p>I am attempting to upload an image from an Android client to my Google App Engine Blobstore and I am encountering problems. All of the relevant posts I have found use the now deprecated HttpEntity. My code results in my server returning a 500 error.</p>
  
  <p>Android client code:</p>
  
  <pre><code>MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
  builder.addPart("file", new FileBody(file, ContentType.MULTIPART_FORM_DATA));
  HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost(url);
  httppost.setEntity(reqEntity.build());
  HttpResponse httpResponse = httpclient.execute(httppost);
  String response = EntityUtils.toString(httpResponse.getEntity());
  </code></pre>
  
  <p>Server (App Engine) code:</p>
  
  <pre><code>public class BlobUpload extends HttpServlet {
    @Override
    private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
  
      public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
  
        Map&lt;String, List&lt;BlobKey&gt;&gt; blobs = blobstoreService.getUploads(req);
        BlobKey blobKey = blobs.get("file").get(0);
  
        res.setStatus(HttpServletResponse.SC_OK);
        res.setContentType("text/plain");
  
        if (blobKey == null) {
          res.getWriter().print("failure");
        } else {
          res.getWriter().print("success");
        }  
     }
  }
  </code></pre>
  
  <p>I have attempted several other permuatations based on examples I have seen all to no avail. This includes setting the Content-Type to Multipart/Form-Data by adding these lines to my client code:</p>
  
  <pre><code>builder.setBoundary("--theboundary--");
  httppost.addHeader("Content-Type", "multipart/form-data; boundary=--theboundary--");
  </code></pre>
  
  <p>I have tested my servlet to make sure it works so I'm positive the problem lies in the way I'm posting my data to my server. I have scoured the MIME and App Engine docs (both of which I find limited) and can't find a solution. Any thoughts/suggestions or working examples would be greatly appreciated.</p>