I would like to send multipart form with video and data such as Email and name. The following is my code and it does not work ,there is no response from the server
File file =new File(VideoPath);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Name", "LDGHT"));
nameValuePairs.add(new BasicNameValuePair("Email", "hhh@example.com"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.setEntity(new FileEntity(file, "video/mp4"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
Check my Post for Sending Mutipart Data Post Data to Server with Multipart..
Also Check this for Reference Link
Upload Video File to Server :
There is my working solution (I hope simpler) for sending image with post, using apache http libraries (very important here is boundary add It won't work without it in my connection). I hope it could help in such situation:
Unfortunately I was not successful to use Venky's code. After two day finally I found my solution and hope it helps those that have same problem. Feel free to modify the code since this code is based on my structure. Note:
bitmapProfileImage
is global variable that holds bitmap image (Bitmap bitmapProfileImage;
)So in your activity/fragment you should have
AsyncTask
class. Add following code insidedoInBackground
method:Finally, in order to use
MultipartEntity
, You are needed to download 4 jar files. One is apache-mime4j and the rest are httpclient, httpcore and httpmime. You should extract jar files and copy/paste it int./libs
folder of your project.Another use full sample