I'm trying to upload a photo from android device to a php website.
For this I'm using MultipartEntity encoding.
For this I added to my project as an external jar file httpmime-4.1-beta1.jar.
What I want to upload to the php website is a image stored on the SDcard.
To this end I'm doing the following in my code:
HttpPost httppost = new HttpPost("....the link to the webiste...");
MultipartEntity reqEntity = new MultipartEntity();
StringBody sb=new StringBody("....");
File file=new File("/sdcard/image.jpg");
FileBody bin = new FileBody(file);
reqEntity.addPart("android",bin);
reqEntity.addPart("id", sb);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
String page = EntityUtils.toString(resEntity);
System.out.println("PAGE :" + page);
}
But the problem with this is that the response from php server is always a broken link.
What I wanna try next is to use
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
But unfortunately the jar I imported doesn't has the class for HttpMultipartMode.BROWSER_COMPATIBLE.So I would really appreciate if you could point me in the right direction-what else should I import for this to work....or how should I upload the image to the server.
I must say that the server is build to upload photo this way:
method="post" enctype="multipart/form-data"
name="form" target="_self" id="form">
<input type="hidden" name="p" value="a" />
Thanks!