I'm trying to do something I thought would be relatively simple: Upload an image to a server with the Android SDK. I'm found a lot of example code:
http://linklens.blogspot.com/2009/06/android-multipart-upload.html
But neither work for me. The confusion I keep running into is what is really needed to make a multipart request. What is the simplest way to have a multipart upload (with an image) for Android?
Any help or advice would be greatly appreciated!
Here is the LIGHT WEIGHTED solution which worked for me with no external HTTPCore and such libs. I was facing issue of 64K methods so have no option left to avoid HTTPCore libraries
USAGE
PHP Code to accept upload
More easy, light (32k), and many more performance:
Android Asynchronous Http Client library: http://loopj.com/android-async-http/
Implementation:
How to send a “multipart/form-data” POST in Android with Volley
Update April 29th 2014:
My answer is kind of old by now and I guess you rather want to use some kind of high level library such as Retrofit.
Based on this blog I came up with the following solution: http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/
You will have to download additional libraries to get
MultipartEntity
running!1) Download httpcomponents-client-4.1.zip from http://james.apache.org/download.cgi#Apache_Mime4J and add apache-mime4j-0.6.1.jar to your project.
2) Download httpcomponents-client-4.1-bin.zip from http://hc.apache.org/downloads.cgi and add httpclient-4.1.jar, httpcore-4.1.jar and httpmime-4.1.jar to your project.
3) Use the example code below.
Then call below
For posterity, I didn't see okhttp mentioned. Related post.
Basically you build up the body using a MultipartBody.Builder, and then post this in a request.
Example in kotlin:
You can you use GentleRequest, which is lightweight library for making http requests(DISCLAIMER: I am the author):
Feel free to check it out: https://github.com/Iprogrammerr/Gentle-Request