0

I am trying to upload an image to server.For that I have added jar files like apache-mime4j,http client,httpcore and httpmime.

And my code is as follows..

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);

    MultipartEntity multiPart = new MultipartEntity();
    multiPart.addPart("my_picture", new FileBody(new File(imagePath.toString())));



    httpPost.setEntity(multiPart);
    HttpResponse res = httpClient.execute(httpPost);


    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String json = reader.readLine();
    JSONTokener tokener = new JSONTokener(json);
    JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
    JSONArray  data = object.getJSONArray("data");
    System.out.println("posted finalResult"+data);

    if (responseEntity != null) {
        responseEntity.consumeContent();
    }

    httpclient.getConnectionManager().shutdown();

The problem is that I am getting an error at the line

multiPart.addPart("my_picture", new FileBody(new File(imagePath.toString())));

And on clicking that error I am getting "Configure build path".

Anyone please tell me what is wrong in my code.

Thanx in advance.

Nikola K.
  • 7,093
  • 13
  • 31
  • 39
svs
  • 377
  • 9
  • 21
  • Look at http://stackoverflow.com/questions/11647140/http-post-no-response/11647224#comment15463797_11647224 and http://stackoverflow.com/questions/7037717/upload-an-image-and-audio-in-one-request-in-android/7038888#7038888 – user370305 Jul 26 '12 at 11:11
  • can you paste full class code. – jeet Jul 26 '12 at 11:12
  • follow this http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/ – Akram Jul 26 '12 at 11:19

0 Answers0