Just to finish this thread off nicely, here's some code to use multipart posts. Again, you need mime4j, httpmime, and Apache Commons IO.
import java.io.ByteArrayInputStream; import java.io.InputStream; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.ContentBody; import org.apache.http.entity.mime.content.InputStreamBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; ... HttpClient httpClient = new DefaultHttpClient(); HttpPost request = new HttpPost("http://www.example.com"); // we assume 'data' is some byte array representing a jpeg InputStream ins = new ByteArrayInputStream(data); parts[0] = new InputStreamBody(ins, "image.jpg"); parts[1] = new StringBody("some bit of information"); parts[2] = new StringBody("another bit of information"); // create the multipart request and add the parts to it MultipartEntity requestContent = new MultipartEntity(); requestContent.addPart("image.jpg", parts[0]); requestContent.addPart("data_part1", parts[1]); requestContent.addPart("data_part2", parts[2]); // execute the request request.setEntity(requestContent); httpClient.execute(request); The HttpClient execute method will give you a handle to the response. >From that you can do HttpResponse.getEntity().getContent() which will give you an InputStream to read the response. Unfortunately the InputStream doesn't produce a meaningful response for InputStream.available(). This might be because somewhere along the way the Content-Length header seems to be getting lost, but I haven't had time to look into this further yet. Cheers, Justin Android Team @ Google On Aug 18, 11:13 pm, code_android_festival_way <[EMAIL PROTECTED]> wrote: > Thank you Justin for helping me out. It is working pretty fine > now. :-) > > Cheers from Germany! > > On 19 Aug., 02:11, "Justin (Google Employee)" <[EMAIL PROTECTED]> wrote: > > > Looks like you also need the Apache Commons IO library which you can > > get fromhttp://commons.apache.org/io/. > > > Cheers, > > Justin > > Android Team @ Google > > > On Aug 18, 3:19 pm, code_android_festival_way > > > <[EMAIL PROTECTED]> wrote: > > > So I'm back with a question. I've imported the libraries mentioned > > > above and got the following setup: > > > >http://paste.pocoo.org/show/82631/ > > > > Now I get an error while executing the POST method with the > > > HttpClient. Am I doing sth. wrong or what do I have to change to get > > > it working. (the paste above is cutted down to the most important > > > parts) > > > > The error message: > > > > Error in ....org.apache.commons.io.ouput.ByteArrayOutputStream > > > > I'm looking forward getting some answers. > > > > Regards! > > > > On 18 Aug., 22:35, code_android_festival_way > > > > <[EMAIL PROTECTED]> wrote: > > > > Thank you for your answer Dan. > > > > > I'm looking now how to get the whole thing working. (since I'm not the > > > > best Java developer :) ) > > > > > I will come back with the results later on. > > > > > On 18 Aug., 22:26, "Dan Morrill" <[EMAIL PROTECTED]> wrote: > > > > > > To shed a bit more light, the reason the multi-part APIs were removed > > > > > is > > > > > because those APIs will not be final in the upstream Apache > > > > > HTTPClient in > > > > > time for Android's schedule for a final 1.0 version. Rather than > > > > > ship an > > > > > early/incompatible API, we chose to remove it, and rely on other > > > > > libraries > > > > > as Justin suggested. > > > > > > Note that this applies only to the multi-part APIs: the rest of the > > > > > Apache > > > > > HTTPClient APIs have been frozen, and so they are "safe" for us to > > > > > include. > > > > > (Seehttp://www.nabble.com/-VOTE--RESULT--HttpClient-4.0-API-freeze-td1863... > > > > > ) > > > > > > - Dan > > > > > > On Mon, Aug 18, 2008 at 1:10 PM, Justin (Google Employee) <[EMAIL > > > > > PROTECTED]>wrote: > > > > > > > Note that this has been removed because it was removed from the > > > > > > Apache > > > > > > HttpClient library that we're bundling. What you want to do is get > > > > > > Mime4j (http://james.apache.org/mime4j/index.html) and HttpMime > > > > > > (http://hc.apache.org/httpcomponents-client/httpmime/index.html) and > > > > > > include these libraries in your Android project. From there, the > > > > > > usage > > > > > > ofmultipartrequests is pretty intuitive. > > > > > > > Cheers, > > > > > > Justin > > > > > > Android Team @ Google > > > > > > > On Aug 18, 1:06 pm, code_android_festival_way > > > > > > <[EMAIL PROTECTED]> wrote: > > > > > > > Hello guys. > > > > > > > > I've seen that themultipartmethod has been removed in 0.9. I'm > > > > > > > wondering now how to achieve these messages now. > > > > > > > > At the moment I'm having something like: > > > > > > > >http://paste.pocoo.org/show/82610/ > > > > > > > > Is there an example how to do that in the 0.9 release? I've > > > > > > > looked at > > > > > > > the Mime4j library but didn't get the point how this works. > > > > > > > > It would be very nice if someone could provide an example for me. > > > > > > > > Regards! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---