title: Why does callback fail after uploading image to Blobstore?
body: <p>I am trying to upload photos to blobstore. The photo gets uploaded succesfully to blobstore but I cannot get the blobkey and servingUrl back. I tried debugging and saw that callback is not made to BlobUpload.java. It gives an error 'Connection to http:// localhost:8888 refused' I am confused because BlobUrlGet.java invokes with no problem and the photo is uploaded. I tried every type of url for the server and the servlets, none of them worked. </p>
  
  <p><strong>EDIT:</strong> I realised that if I manually change the 'localhost:8888'  to '10.0.2.2:8888' in the debug mode (str variable), 'connection refused' problem goes away but this time it shows below error.  </p>
  
  <p>http:// localhost:8888/_ah/upload/ahFteWZpcnN0YXBwZGVtbzEyM3IiCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGICAgICAgN4KDAError 405 HTTP method POST is not supported by this URL
  <h2>Error 405 HTTP method POST is not supported by this URL</h2>
  </p>
  
  <p>This is the return from post method. It is the same error when I deploy to appengine and work from there.</p>
  
  <p>My code is as below.</p>
  
  <p>BlobUrlGet.java </p>
  
  <pre><code>public class BlobUrlGet extends HttpServlet{   
      BlobstoreService blServ = BlobstoreServiceFactory.getBlobstoreService();    
      public void doGet(HttpServletRequest req, HttpServletResponse resp)
              throws IOException {  
          String blobUploadUrl = blServ.createUploadUrl("/blob");   
          resp.setStatus(HttpServletResponse.SC_OK);
          resp.setContentType("text/plain");    
          PrintWriter out = resp.getWriter();
          out.print(blobUploadUrl);
      }       
  }
  </code></pre>
  
  <p>BlobUpload.java</p>
  
  <pre><code>public class BlobUpload extends HttpServlet {
      BlobstoreService blobstoreService = BlobstoreServiceFactory
              .getBlobstoreService();
  
      public void doPost(HttpServletRequest req, HttpServletResponse resp)
              throws IOException {
          try {
              List&lt;BlobKey&gt; blobs = blobstoreService.getUploads(req).get("file");
              BlobKey blobKey = blobs.get(0);
  
              ImagesService imagesService = ImagesServiceFactory
                      .getImagesService();
              ServingUrlOptions servingOptions = ServingUrlOptions.Builder
                      .withBlobKey(blobKey);
  
              String servingUrl = imagesService.getServingUrl(servingOptions);
  
              resp.setStatus(HttpServletResponse.SC_OK);
              resp.setContentType("application/json");
  
              JSONObject json = new JSONObject();
  
              json.put("servingUrl", servingUrl);
              json.put("blobKey", blobKey.getKeyString());
  
              PrintWriter out = resp.getWriter();
              out.print(json.toString());
              out.flush();
              out.close();
          } catch (JSONException e) {
  
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>Android client</p>
  
  <pre><code>private class GetBlobUrlTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected Void doInBackground(Void... arg0){  
  
          HttpClient httpClient = new DefaultHttpClient();    
          //This will invoke "ImgUpload servlet           
          HttpGet httpGet = new HttpGet("http://10.0.2.2:8888/bloburl"); 
          HttpResponse response;
          try {
              response = httpClient.execute(httpGet);         
              HttpEntity urlEntity = response.getEntity();
              InputStream in = urlEntity.getContent();
              String str = ""; 
              StringWriter writer = new StringWriter();
              String encoding = "UTF-8";
              IOUtils.copy(in, writer, encoding);
              str = writer.toString();
  //              str = URLDecoder.decode(str, "UTF-8");
                  HttpPost httppost = new HttpPost(str);
                  File f = new File(picturePath);
                  FileBody fileBody = new FileBody(f);
                  MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
                  reqEntity.addPart("file", fileBody);
                  reqEntity.addBinaryBody("Photo", f, ContentType.create("image/jpeg"), "foto2.jpg");
                  httppost.setEntity(reqEntity.build());
                  response = httpClient.execute(httppost); //Here "uploaded" servlet is automatically       invoked
                  urlEntity = response.getEntity(); //Response will be returned by "uploaded" servlet in JSON format
                  in = urlEntity.getContent();
                  str = "";
                  IOUtils.copy(in, writer, encoding);
                  str = writer.toString();
                  JSONObject resultJson = new JSONObject(str);
                  blobKey = resultJson.getString("blobKey");
                  servingUrl = resultJson.getString("servingUrl");    
  
  
  
          } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          return null;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>  &lt;servlet&gt;
      &lt;servlet-name&gt;BlobstoreURL&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.google.samplesolutions.mobileassistant.BlobUrlGet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;BlobstoreURL&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/bloburl&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;BlobstoreUpload&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.google.samplesolutions.mobileassistant.BlobUpload&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;BlobstoreUpload&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/blob&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>