I’m looking for simple and clean solution for HTTP multipart post, which will send some Strings (form data) and several files with streaming support. (files needs to be streamed to avoid out of memory error)
I’d like to achieve this with the built-in “org.apache.httpclient” if possible.
I was able to create a clean solution with HttpURLConnection.
Despite all my efforts with this solution strings were sent with 8859-x encoding instead of UTF-8.
EDIT: My code is available at MultiPart with HttpURLConnection source
I created an output stream with this code:
HttpURLConnection connection = setupConnection();
dataOutputStream = new DataOutputStream(connection.getOutputStream());
After this I just wrote the data with dataOutputStream.writeBytes
If i could get an outputstream from httpclient it would be great, however it seems it works a different way.
Any help is appreciated.
Thanks
I’ve just created a simple solution for this: android_multipart_entity.
It’s free (including for commercial usage), however if this is possible please keep references to me inside of my classes.
It’s designed to be used with the built in Android
HttpClient. Sample usage code:EDIT:
I reviewed your MultiPart with HttpURLConnection code. You get UTF-8 issue because of
DataOutputStreamusage. API says for that class:This class just does not suit your needs. In order to read the data you would have to have its direct opposite –
DataInputStreamon the other end.So my advice would be to use plain
OutputStream. And write bytes to it. Smth like this: