Thanks!

According to a Java-expert friend, the code looks OK and the problem
is probably with the import script (though I've yet to confirm this).

I'll update when I find out, and post an example of the code that
definitely works.

On 16 Dec, 00:04, Tom <thomasfmc...@gmail.com> wrote:
> Check out this 
> posthttp://www.anddev.org/setting_up_multipart_messages_using_the_default...
>
> Also check the length of the image part since for me it was always
> zero.
>
> On Dec 14, 5:49 pm, Anna PS <annapowellsm...@googlemail.com> wrote:
>
>
>
> > Hi,
>
> > I'm trying to POST a jpeg image as part of a multipart message, and
> > keep getting errors saying the file is incorrect.
>
> > The jpeg data is retrieved from the photo store using its URI. This
> > bit seems to work fine.
>
> > All the other parts of the multipart message also work fine, and I
> > know that there isn't a problem with the POST script.
>
> > Unfortunately the error message isn't very descriptive - it just says
> > "Please upload a JPEG image only".
>
> > I think the problem is something to do with the conversion from bitmap
> > to jpeg to ByteArrayPartSource. Should I use some method other than
> > FilePart for uploading jpegs?
>
> > My code is below...
>
> > Thanks
> > Anna
>
> > --------------------------------
>
> > method = new PostMethod(url);
>
> > try {
>
> >                                 Bitmap bitmap;
> >                                 ByteArrayOutputStream bytes;
> >                                 byte[] imageData = null;
>
> >                                 HttpClient client = new HttpClient();
> >                                 
> > client.getHttpConnectionManager().getParams()
> >                                                 .setConnectionTimeout(5000);
>
> >                                 //Get photo from URI
> >                                 bitmap = 
> > android.provider.MediaStore.Images.Media.getBitmap(
> >                                                 getContentResolver(), uri);
> >                                 bytes = new ByteArrayOutputStream();
>
> >                                 //Compress to jpeg
> >                                 bitmap.compress(Bitmap.CompressFormat.JPEG, 
> > 100, bytes);
>
> >                                 imageData = bytes.toByteArray();
>
> >                                //length is not null, so I know there
> > is something there
> >                                 Log.d(LOG_TAG, "len of data is " + 
> > imageData.length + " bytes");
>
> >                                 Part[] parts = { new StringPart("name", 
> > name),
> >                                                 new StringPart("email", 
> > email),
> >                                                 new FilePart("photo", new 
> > ByteArrayPartSource("photo",
> >                                                                 imageData))
> >                                                 };
>
> >                                 method.setRequestEntity(new 
> > MultipartRequestEntity(parts,
> >                                                 method.getParams()));
>
> >                                 client.executeMethod(method);
> >                                 responseString = 
> > method.getResponseBodyAsString();
> >                                 method.releaseConnection();
>
> >                                 Log.e("httpPost", "Response status: " + 
> > responseString);
>
> >                                 textMsg.setText(" Response: " + 
> > responseString);
>
> > } catch (Exception ex) {
>
> >                                 Log.v(LOG_TAG, "Exception", ex);
> >                                 return false;} finally {
>
> >                                 method.releaseConnection();
>
> > }- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to