title: Upload image to the server using multipartentity and json in android
body: <p>I have read lots of post to achieve the task like to upload image along with parameters using multipartentity and josn in android, but my problem is when i was trying to upload image and parameter without converting string to <code>JSONobject</code> then image has uploaded without an error but when i was trying to add response string to jsonobject then error occur in the logcat like ):</p>
  
  <pre><code>error: Value`&lt;form of type java.lang.String cannot be converted to JSONObject.
  </code></pre>
  
  <p>Any one please help to resolve this issue? I want to send an image and <code>JsonObjec</code>t to an PHP Server with <code>MultipartEntity</code>. I am working on an app that allows the user upload an image by using H<code>ttpPost</code> method. I use <code>MultipartEntity</code> and therefore I added the libraries apache-mime4j-0.6.1.jar, httpclient-4.3.1.jar, httpcore-4.3.1.jar and httpmime-4.2.1.jar into my app.</p>
  
  <p>Here is my Code:</p>
  
  <pre><code>    public JSONObject doFileUpload(String _fname, String _lname, String _email,
                  String _password, String _country, String _countrycode,
                  String _phone) {
  
              File file1 = new File(selectedPath);
              String urlString = "http://capstonehostingservices.com/fetch_new/app/index.php/fetch/register";
              try {
                  HttpClient client = new DefaultHttpClient();
                  HttpPost post = new HttpPost(urlString);
                  FileBody bin1 = new FileBody(file1);
                  MultipartEntity reqEntity = new MultipartEntity();
                  reqEntity.addPart("photo", bin1);
                  reqEntity.addPart("first_name", new StringBody(_fname));
                  reqEntity.addPart("last_name", new StringBody(_lname));
                  reqEntity.addPart("email", new StringBody(_email));
                  reqEntity.addPart("password", new StringBody(_password));
                  reqEntity.addPart("country", new StringBody(_country));
                  reqEntity.addPart("country_code", new StringBody(_countrycode));
                  reqEntity.addPart("phone", new StringBody(_phone));
  
                  post.setEntity(reqEntity);
                  HttpResponse response = client.execute(post);
                  resEntity = response.getEntity();
                   String response_str = EntityUtils.toString(resEntity);
  
  
  
                      json = new JSONObject(response_str);
  
  
              } catch (Exception ex) {
                  Log.e("Debug", "error: " + ex.getMessage(), ex);
              }
              return json;
          }
  </code></pre>
  
  <p>In above code i was trying to convert response string to jsonobject, how to i achieve this?
  I used selectedpath parameter as to get image path from gallary, I want to send an image and a <code>JsonObject</code> to an PHP Server with <code>MultipartEntity</code>. I am working on an app that allows the user upload an image by using <code>HttpPost</code> method. I use <code>MultipartEntity</code> and therefore I added the libraries apache-mime4j-0.6.1.jar, httpclient-4.3.1.jar, httpcore-4.3.1.jar and httpmime-4.2.1.jar into my app.</p>