I want to upload image using MultipartEntity , I have added all external jar files.
But when I try to use below code I get class not found error , and image is not able to upload.
Now I restart eclipse , Now I get error like
Unable to execute dex: Multiple dex files define Lorg/apache/http/entity/mime/FormBodyPart;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/http/entity/mime/FormBodyPart;
Below is my php file and java code.
<?php
$photo = $_FILES['photo']['name'];
if(!empty($_FILES['photo']['name']))
{
move_uploaded_file($_FILES['photo']['tmp_name'], "User_files/".$_FILES['photo']['name']);
}
?>
.
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
File file = new File(Environment.getExternalStorageDirectory()+"/a.png");
//Log.d(TAG, "UPLOAD: setting up multipart entity");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//Log.d(TAG, "UPLOAD: file length = " + file.length());
//Log.d(TAG, "UPLOAD: file exist = " + file.exists());
mpEntity.addPart("photo", new FileBody(file, "image/png"));
//mpEntity.addPart("id", new StringBody("1"));
httppost.setEntity(mpEntity);
HttpResponse response;
try {
response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
}
if (resEntity != null) {
resEntity.consumeContent();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}