actually i found a way to post the image by creating my own
AbstractContentBody<http://www.anddev.org/multimedia-problems-f28/post-with-image-attachment-t50630.html>instead
of
InputStreamBody but i really wonder why this doesnt work.

2011/1/27 ugur <[email protected]>

> thanx for reply
>
> what do u mean with format?
> i guess there is a problem on line that sends image ByteArrayInputStream :
>
> entity.addPart("jpg",new InputStreamBody(new
> ByteArrayInputStream(byteData),"jpeg"));
>
> because it posts stringBody successfuly.
>
> 2011/1/24 Kumar Bibek <[email protected]>
>
> You should first check what format your server accepts requests for
>> this particular call. This is a little bit tricky, but you should be
>> able to get it working.
>>
>> On Jan 23, 3:14 am, ugurbayram <[email protected]> wrote:
>> > hi everyone. im new in android dev and stuck on posting an image to
>> > jersey web service.
>> > here is code snipets of android app and web service.
>> >
>> > Android app
>> >
>> >                         HttpClient httpClint = new
>> > DefaultHttpClient();
>> >                         HttpPost httpPost = new HttpPost(BASE_URI);
>> >                         MultipartEntity entity = new
>> > MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
>> >
>> >                         Bitmap bmImg =
>> BitmapFactory.decodeFile("sdcard/22_6185.jpg");
>> >                         ByteArrayOutputStream bos = new
>> ByteArrayOutputStream();
>> >                         bmImg.compress(CompressFormat.JPEG, 100, bos);
>> >                         byte[] bitmapdata = bos.toByteArray();
>> >
>> >                         entity.addPart("Default",new
>> StringBody("Default",
>> > Charset.forName("UTF-8")));
>> >                         entity.addPart("6",new
>> StringBody("6",Charset.forName("UTF-8")));
>> >                         entity.addPart("100", new
>> > StringBody("100",Charset.forName("UTF-8")));
>> >                         entity.addPart("jpg",new InputStreamBody(new
>> > ByteArrayInputStream(byteData),"jpeg"));
>> >                                 httpPost.setEntity(entity);
>> >                         HttpResponse httpResponse =
>> httpClint.execute(httpPost);
>> >
>> > Web service
>> >
>> > try {
>> >             newSearchOption =
>> > getStringFromInputStream(((BodyPartEntity)
>> > multipart.getBodyParts().get(0).getEntity()).getInputStream());
>> >             newCategoryName =
>> > getStringFromInputStream(((BodyPartEntity)
>> > multipart.getBodyParts().get(1).getEntity()).getInputStream());
>> >             newCategoryId = Integer.parseInt(newCategoryName);
>> >             numberOfResult =
>> > getIntegerFromInputStream(((BodyPartEntity)
>> > multipart.getBodyParts().get(2).getEntity()).getInputStream());
>> >             BodyPartEntity bpe = (BodyPartEntity)
>> > multipart.getBodyParts().get(3).getEntity();
>> >             InputStream is = bpe.getInputStream();
>> >             bufferedImage = ImageIO.read(is);
>> >         } catch (IOException e) {
>> >             e.printStackTrace();
>> >         }
>> >
>> > and here is the error message a receive everytime :
>> >
>> > HTTP Status 415 - Status report
>> > message
>> > description
>> > The server refused this request because the request entity is in a
>> > format not supported by the requested resource for the requested
>> > method ().
>> > GlassFish Server Open Source Edition 3.0.1
>> >
>> > it seems there is a problem on entity parts but couldnt figure out.
>> > i tried afew more code snipets on this forum eigther but nothing
>> > changed.
>> >
>> > thanks in a advance
>>
>> --
>> 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]<android-developers%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>

-- 
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

Reply via email to