Check out this post http://www.anddev.org/setting_up_multipart_messages_using_the_defaulthttpclient-t3036.html
Also check the length of the image part since for me it was always zero. On Dec 14, 5:49 pm, Anna PS <[email protected]> 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(); > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

