Guest User

Untitled

a guest
Aug 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. No response from server when uploading video
  2. HttpClient client = new DefaultHttpClient();
  3. client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
  4.  
  5. HttpPost post = new HttpPost(url);
  6. MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
  7.  
  8.  
  9. File file= new File(sourceFileUri);// sourceFileUri is a String variable , contains the path of video
  10. FileBody bin = new FileBody(file);
  11. // For usual String parameters
  12.  
  13. entity.addPart( "name", new StringBody( "xxxxx", "text/plain",
  14. Charset.forName( "UTF-8" )));
  15.  
  16. entity.addPart( "Phone", new StringBody( "0023451234", "text/plain",
  17. Charset.forName( "UTF-8" )));
  18.  
  19. entity.addPart( "file", bin);
  20.  
  21.  
  22. post.setEntity( entity );
  23.  
  24. // Here we go!
  25. // String response = EntityUtils.toString( client.execute( post ).getEntity(), "UTF-8" );
  26. HttpResponse response = client.execute(post);
  27. HttpEntity resEntity = response.getEntity();
  28. if (resEntity != null) {
  29. Toast.makeText(getApplicationContext(),EntityUtils.toString(resEntity), Toast.LENGTH_SHORT).show();
  30. Log.i("RESPONSE",EntityUtils.toString(resEntity));
  31. }
  32. }
  33. catch (Exception e) {
  34. e.printStackTrace();
  35. }
Add Comment
Please, Sign In to add comment