[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
I think there is another way to approach this which cuts out the need for the libraries, but you'll need to get the AOSP source. Once you've checked out the source from frameworks_base you can re-use an implementation available internally in Android from; frameworks/base/core/java/com/android/internal/http/multipart The instructions on how to use it are in the header comments of MultipartEntity.java Given the problems with kernel.org you can pick up the source code from the **unofficial** github mirror at https://github.com/android/platform_frameworks_base as a quick workaround to the kernel.org issues. Al. P.S. Don't forget to keep to the licensing terms :). -- T: @alsutton W: www.funkyandroid.com The views expressed in this email are those of the author and not necessarily those of Funky Android Limited, it's associates, or it's subsidiaries. -- 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 android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
@Joe LaPenna I am trying to send multipart to google appengine as well and struggling. Do you have any specific instructions that might help? On Oct 12, 12:56 am, Joe LaPenna [EMAIL PROTECTED] wrote: By chance is the web server google app engine? Even if it isn't there is a chance your server does not support chunked transfer encoding. If for example any part of your multipart message is an inputstream part then the library will set the post using chunked encoding. I got around this in gae creating my own inputstream. Part that supported getcontentlenght and the other method that specified that reading the stream did not consume it. (I returned a copy of the stream when it is requesrted). Sorry if this is a bit vague, I'm away from the code I wrote at the moment. On Oct 7, 2008 8:52 PM, Vinod B [EMAIL PROTECTED] wrote: hi, I am sending an http post of a multipart (form-data) as shown below to an apache web server. It returns an error saying the Content-length header needs to be specified. Looking at the trace, the Content-Length header is indeed not being set in the request. I tried getting the content length using requestContent.getContentLength () only to get -1. So any pointers on what to do for this problem? thanks, -Vinod On Aug 19, 4:18 pm, Justin (Google Employee) [EMAIL PROTECTED] wrote: Just to finish this thread off nicely, here's some code to usemultipartposts. 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 themultipartrequest 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
By chance is the web server google app engine? Even if it isn't there is a chance your server does not support chunked transfer encoding. If for example any part of your multipart message is an inputstream part then the library will set the post using chunked encoding. I got around this in gae creating my own inputstream. Part that supported getcontentlenght and the other method that specified that reading the stream did not consume it. (I returned a copy of the stream when it is requesrted). Sorry if this is a bit vague, I'm away from the code I wrote at the moment. On Oct 7, 2008 8:52 PM, Vinod B [EMAIL PROTECTED] wrote: hi, I am sending an http post of a multipart (form-data) as shown below to an apache web server. It returns an error saying the Content-length header needs to be specified. Looking at the trace, the Content-Length header is indeed not being set in the request. I tried getting the content length using requestContent.getContentLength () only to get -1. So any pointers on what to do for this problem? thanks, -Vinod On Aug 19, 4:18 pm, Justin (Google Employee) [EMAIL PROTECTED] wrote: Just to finish this thread off nicely, here's some code to usemultipartposts. 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 themultipartrequest 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Hi James, I downloaded the apache common jars and added them to my build path, but still I get org.apache.http.entity.mime cant be resolved. Don't know if I'm doing something wrong. I just followed the steps you had explained. Kindly let me know if there is anything extra I should do with eclipse. Thanks and regards, Rajesh On Aug 27, 12:12 pm, jlapenna [EMAIL PROTECTED] wrote: Yeah, you're going to need to add it to your build path. You can do that by right clicking on your project in the Package Explorer, selecting Build Path - Configure Build Path, clicking on Libraries then clicking Add JARs. If nothing is listed you need to add the libraries to your project, you can do that by creating a new folder in your project called lib, and copying the .jar files recommended above in that directory and then right clicking on that folder and clicking refresh. At that point the libraries should be listed in the Add JARs dialog. On Aug 26, 7:49 pm, Zack [EMAIL PROTECTED] wrote: Thanks for your many helpful posts! I'm sure this one will be helpful to me but what do I need to do to be able to import org.apache.http.entity.mime.MultipartEntity;? I get The import org.apache.http.entity.mime cannot be resolved Do I need to configure eclipse and add something to it? Thanks again. On Aug 19, 4:18 pm, Justin (Google Employee) [EMAIL PROTECTED] wrote: 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Yeah, you're going to need to add it to your build path. You can do that by right clicking on your project in the Package Explorer, selecting Build Path - Configure Build Path, clicking on Libraries then clicking Add JARs. If nothing is listed you need to add the libraries to your project, you can do that by creating a new folder in your project called lib, and copying the .jar files recommended above in that directory and then right clicking on that folder and clicking refresh. At that point the libraries should be listed in the Add JARs dialog. On Aug 26, 7:49 pm, Zack [EMAIL PROTECTED] wrote: Thanks for your many helpful posts! I'm sure this one will be helpful to me but what do I need to do to be able to import org.apache.http.entity.mime.MultipartEntity;? I get The import org.apache.http.entity.mime cannot be resolved Do I need to configure eclipse and add something to it? Thanks again. On Aug 19, 4:18 pm, Justin (Google Employee) [EMAIL PROTECTED] wrote: 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
How does you resolve this error? Thanks On 22 août, 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems with multipart entities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229):VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229):VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229):VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 01:11:12.972: WARN/System.err(229): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 01:11:12.972: WARN/System.err(229): at dalvik.system.NativeStart.main(Native Method) could you pls help me with that? On Aug 18, 8:11 pm, 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Thanks for your many helpful posts! I'm sure this one will be helpful to me but what do I need to do to be able to import org.apache.http.entity.mime.MultipartEntity;? I get The import org.apache.http.entity.mime cannot be resolved Do I need to configure eclipse and add something to it? Thanks again. On Aug 19, 4:18 pm, Justin (Google Employee) [EMAIL PROTECTED] wrote: 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
I got another question regarding that topic. I'm letting my user pic a photo from the Image ContentProvider. After that I'm getting back an Uri which represents the image in the ContentProvider. Now I'm wondering which is the easiest way to get that picture which is represented by an Uri into a FileBody or InputStreamBody. I didn't find a chance to create a File object out of the Uri. My second try was to put my InputStream which I get from openInputStream(Uri uri) into the InputStreamBody but now I'm wondering which could be the name for that file? (I even dont know the type of the image. Is it a jpg or png or sth. else) So it would be nice if someone could help me with that. Regards! On 23 Aug., 06:20, shotwave [EMAIL PROTECTED] wrote: the problem was with missing uses-permission android:name=android.permission.INTERNET / permission in AndroidManfest.xml. As soon as I have set it and __removed .android folder__ everything started working! On Aug 22, 10:16 pm, shotwave [EMAIL PROTECTED] wrote: thank you, guys On Aug 22, 3:01 am, code_android_festival_way [EMAIL PROTECTED] wrote: Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this waymultipartmessages work quite fine. Regards! On 22 Aug., 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems withmultipartentities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Well I've managed it to add representation of the Uri to a multipart message. And here is the way I did it: http://paste.pocoo.org/show/83196/ It is working quite fine. Regards! On 24 Aug., 15:46, code_android_festival_way [EMAIL PROTECTED] wrote: I got another question regarding that topic. I'm letting my user pic a photo from the Image ContentProvider. After that I'm getting back an Uri which represents the image in the ContentProvider. Now I'm wondering which is the easiest way to get that picture which is represented by an Uri into a FileBody or InputStreamBody. I didn't find a chance to create a File object out of the Uri. My second try was to put my InputStream which I get from openInputStream(Uri uri) into the InputStreamBody but now I'm wondering which could be the name for that file? (I even dont know the type of the image. Is it a jpg or png or sth. else) So it would be nice if someone could help me with that. Regards! On 23 Aug., 06:20, shotwave [EMAIL PROTECTED] wrote: the problem was with missing uses-permission android:name=android.permission.INTERNET / permission in AndroidManfest.xml. As soon as I have set it and __removed .android folder__ everything started working! On Aug 22, 10:16 pm, shotwave [EMAIL PROTECTED] wrote: thank you, guys On Aug 22, 3:01 am, code_android_festival_way [EMAIL PROTECTED] wrote: Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this waymultipartmessages work quite fine. Regards! On 22 Aug., 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems withmultipartentities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this way multipart messages work quite fine. Regards! On 22 Aug., 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems with multipart entities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 01:11:12.972: WARN/System.err(229): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 01:11:12.972: WARN/System.err(229): at dalvik.system.NativeStart.main(Native Method) could you pls help me with that? On Aug 18, 8:11 pm, 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!
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Hello I has the same problem and your post resolt it! thanks On 22 août, 09:01, code_android_festival_way [EMAIL PROTECTED] wrote: Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this way multipart messages work quite fine. Regards! On 22 Aug., 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems with multipart entities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 01:11:12.972: WARN/System.err(229): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 01:11:12.972: WARN/System.err(229): at dalvik.system.NativeStart.main(Native Method) could you pls help me with that? On Aug 18, 8:11 pm, 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
thank you, guys On Aug 22, 3:01 am, code_android_festival_way [EMAIL PROTECTED] wrote: Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this way multipart messages work quite fine. Regards! On 22 Aug., 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems with multipart entities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 01:11:12.972: WARN/System.err(229): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 01:11:12.972: WARN/System.err(229): at dalvik.system.NativeStart.main(Native Method) could you pls help me with that? On Aug 18, 8:11 pm, 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
unfortunately now I get new error 08-22 22:19:15.494: WARN/System.err(193): java.net.SocketException: unknown error 08-22 22:19:15.534: WARN/System.err(193): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native Method) 08-22 22:19:15.544: WARN/System.err(193): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java: 79) 08-22 22:19:15.554: WARN/System.err(193): at org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java: 59) 08-22 22:19:15.564: WARN/System.err(193): at java.net.Socket.checkClosedAndCreate(Socket.java:763) 08-22 22:19:15.564: WARN/System.err(193): at java.net.Socket.connect(Socket.java:910) 08-22 22:19:15.564: WARN/System.err(193): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java: 117) 08-22 22:19:15.564: WARN/System.err(193): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java: 129) 08-22 22:19:15.584: WARN/System.err(193): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java: 164) 08-22 22:19:15.594: WARN/System.err(193): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java: 119) 08-22 22:19:15.604: WARN/System.err(193): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java: 348) 08-22 22:19:15.604: WARN/System.err(193): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java: 555) 08-22 22:19:15.604: WARN/System.err(193): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java: 487) 08-22 22:19:15.604: WARN/System.err(193): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java: 465) 08-22 22:19:15.604: WARN/System.err(193): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:86) 08-22 22:19:15.604: WARN/System.err(193): at android.view.View.performClick(View.java:2068) 08-22 22:19:15.644: WARN/System.err(193): at android.view.View.onTouchEvent(View.java:3453) 08-22 22:19:15.644: WARN/System.err(193): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 22:19:15.644: WARN/System.err(193): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 22:19:15.644: WARN/System.err(193): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 22:19:15.644: WARN/System.err(193): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 22:19:15.644: WARN/System.err(193): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 22:19:15.694: WARN/System.err(193): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 22:19:15.694: WARN/System.err(193): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 22:19:15.694: WARN/System.err(193): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 22:19:15.694: WARN/System.err(193): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 22:19:15.694: WARN/System.err(193): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 22:19:15.714: WARN/System.err(193): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 22:19:15.734: WARN/System.err(193): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 22:19:15.744: WARN/System.err(193): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 22:19:15.754: WARN/System.err(193): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 22:19:15.754: WARN/System.err(193): at android.os.Looper.loop(Looper.java:123) 08-22 22:19:15.754: WARN/System.err(193): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 22:19:15.754: WARN/System.err(193): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 22:19:15.754: WARN/System.err(193): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 22:19:15.754: WARN/System.err(193): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 22:19:15.774: WARN/System.err(193): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 22:19:15.784: WARN/System.err(193): at dalvik.system.NativeStart.main(Native Method) my OS is ubutu 8.04 On Aug 22, 6:17 pm, barbapapaz [EMAIL PROTECTED] wrote: Hello I has the same problem and your post resolt it! thanks On 22 août, 09:01, code_android_festival_way [EMAIL PROTECTED] wrote: Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this way multipart messages work quite fine. Regards! On 22 Aug., 07:16,
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
the problem was with missing uses-permission android:name=android.permission.INTERNET / permission in AndroidManfest.xml. As soon as I have set it and __removed .android folder__ everything started working! On Aug 22, 10:16 pm, shotwave [EMAIL PROTECTED] wrote: thank you, guys On Aug 22, 3:01 am, code_android_festival_way [EMAIL PROTECTED] wrote: Hello! I have done it the following way: http://paste.pocoo.org/show/GwHe8LrG9DCnq4zuphmK/ (note that this is just a sample code the HttpClient needs some setup) Using it this way multipart messages work quite fine. Regards! On 22 Aug., 07:16, shotwave [EMAIL PROTECTED] wrote: I also have problems with multipart entities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 01:11:12.972: WARN/System.err(229): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 01:11:12.972: WARN/System.err(229): at dalvik.system.NativeStart.main(Native Method) could you pls help me with that? On Aug 18, 8:11 pm, 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
I also have problems with multipart entities, so I have followed the recomendations given here and added mime4j and httpmime as the libraries to my eclipse project, however once I have started the app and tried to upload some data I have got an exception 08-22 01:11:12.672: WARN/dalvikvm(229): VFY: unable to resolve new- instance 255 (Lorg/apache/commons/io/output/ByteArrayOutputStream;) in Lorg/apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.682: WARN/dalvikvm(229): VFY: rejecting opcode 0x22 at 0x0031 08-22 01:11:12.692: WARN/dalvikvm(229): VFY: rejected Lorg/apache/ http/entity/mime/HttpMultipart;.getTotalLength ()J 08-22 01:11:12.692: WARN/dalvikvm(229): Verifier rejected class Lorg/ apache/http/entity/mime/HttpMultipart; 08-22 01:11:12.722: WARN/System.err(229): java.lang.VerifyError: org.apache.http.entity.mime.HttpMultipart 08-22 01:11:12.782: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 76) 08-22 01:11:12.852: WARN/System.err(229): at org.apache.http.entity.mime.MultipartEntity.init(MultipartEntity.java: 99) 08-22 01:11:12.862: WARN/System.err(229): at com.sphericbox.jigsaw.LoginActivity $YesClickListener.onClick(LoginActivity.java:78) 08-22 01:11:12.862: WARN/System.err(229): at android.view.View.performClick(View.java:2068) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.onTouchEvent(View.java:3453) 08-22 01:11:12.872: WARN/System.err(229): at android.widget.TextView.onTouchEvent(TextView.java:4347) 08-22 01:11:12.872: WARN/System.err(229): at android.view.View.dispatchTouchEvent(View.java:3108) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.872: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.902: WARN/System.err(229): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:841) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.superDispatchTouchEvent(PhoneWindow.java:1552) 08-22 01:11:12.912: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java: 1059) 08-22 01:11:12.932: WARN/System.err(229): at android.app.Activity.dispatchTouchEvent(Activity.java:1872) 08-22 01:11:12.932: WARN/System.err(229): at com.android.internal.policy.impl.PhoneWindow $DecorView.dispatchTouchEvent(PhoneWindow.java:1536) 08-22 01:11:12.932: WARN/System.err(229): at android.view.ViewRoot.handleMessage(ViewRoot.java:1088) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Handler.dispatchMessage(Handler.java:88) 08-22 01:11:12.932: WARN/System.err(229): at android.os.Looper.loop(Looper.java:123) 08-22 01:11:12.932: WARN/System.err(229): at android.app.ActivityThread.main(ActivityThread.java:3708) 08-22 01:11:12.962: WARN/System.err(229): at java.lang.reflect.Method.invokeNative(Native Method) 08-22 01:11:12.972: WARN/System.err(229): at java.lang.reflect.Method.invoke(Method.java:492) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:734) 08-22 01:11:12.972: WARN/System.err(229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492) 08-22 01:11:12.972: WARN/System.err(229): at dalvik.system.NativeStart.main(Native Method) could you pls help me with that? On Aug 18, 8:11 pm, 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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
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 of multipart requests 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 the multipart method 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 -~--~~~~--~~--~--~---
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
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
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
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 of multipart requests 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 the multipart method 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 -~--~~~~--~~--~--~---
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
On Mon, Aug 18, 2008 at 1:06 PM, code_android_festival_way [EMAIL PROTECTED] wrote: Hello guys. I've seen that the multipart method has been removed in 0.9. That's surprising. It's common knowledge that multi part mime is necessary in mobile, due to the performance gains and user experience in getting complete pages of info. Guess you will need to parse the boundaries yourself. Shane --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
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. (See http://www.nabble.com/-VOTE--RESULT--HttpClient-4.0-API-freeze-td18634158.html ) - 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 of multipart requests 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 the multipart method 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 -~--~~~~--~~--~--~---
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
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 of multipart requests 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 the multipart method 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 -~--~~~~--~~--~--~---
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
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 of multipart requests 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 the multipart method 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 -~--~~~~--~~--~--~---
[android-developers] Re: Multipart Messages - Is there an example how to get them work now. (Uploading to a web API)
Looks like you also need the Apache Commons IO library which you can get from http://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 of multipart requests 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 the multipart method 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 -~--~~~~--~~--~--~---