3

i'm creating an activity which needs to upload an image to a webservice using their api.

I found that if i use UrlEncodedFormEntity and send the image data through that. the webservice doesn't receive that. ( at least it will not be able to read that .)

In fact if i add some vars to send with the image data ( like name of the file, filesize ) they can be read from the webservice but the image data still doesn't appear if i try to read it serverside.

Right now i'm using UrlEncodedFormEntity with BasicNameValuePair as container for my data.

Andrea Baccega
  • 27,211
  • 13
  • 45
  • 46

1 Answers1

2

May be it will help you. I've used the same functionality, but the web service was developed by me. I've post the image using the following:

  1. I get the particular Bitmap icon and compress it in byte array like this:

    ByteArrayOutputStream out = new ByteArrayOutputStream(10240);
    icon.compress(CompressFormat.PNG, 100, out);
    
  2. Then create HttpPost and set the the entity.

    httpPostInstance.setEntity(new ByteArrayEntity(out.toByteArray()));
    
  3. Check the "Content-type" header. You must properly set it to whatever your service expect.

Sga
  • 3,608
  • 2
  • 36
  • 47
ponkin
  • 2,363
  • 18
  • 25