Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. String url = "http://yourserver.com/upload.php";
  2. File file = new File("myfileuri");
  3. try {
  4. HttpClient httpclient = new DefaultHttpClient();
  5.  
  6. HttpPost httppost = new HttpPost(url);
  7.  
  8. InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);
  9. reqEntity.setContentType("binary/octet-stream");
  10. reqEntity.setChunked(true); // Send in multiple parts if needed
  11. httppost.setEntity(reqEntity);
  12. HttpResponse response = httpclient.execute(httppost);
  13. //Do something with response...
  14.  
  15. } catch (Exception e) {
  16. e.printStackTrace();
  17. }
  18.  
  19. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  20.  
  21. File myFile = new File("/path/to/file.png");
  22. RequestParams params = new RequestParams();
  23. try {
  24. params.put("profile_picture", myFile);
  25. } catch(FileNotFoundException e) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement