I have looked and searched, but I can't find a good answer. I need to upload files to a server. I can't seem to find a good package or tutorial that helps me to do this. I know how to do the upload on the server end (PHP), but not how to do this with Android.
Asked
Active
Viewed 77 times
0
-
Googling "android upload files to server" results in [this answer](http://stackoverflow.com/questions/4126625/how-to-send-a-file-in-android-from-mobile-to-server-using-http) – adelphus Aug 25 '15 at 17:31
1 Answers
0
Use this code:
HttpPost req = new HttpPost(composeTargetUrl());
MultipartEntity entity = new MultipartEntity();
entity.addPart(POST_IMAGE_VAR_NAME, new FileBody(toUpload));
try {
entity.addPart(POST_SESSION_VAR_NAME, new StringBody(uploadSessionId));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
req.setEntity(entity);
Reference: How to send a “multipart/form-data” POST in Android with Volley