1

I'm trying to figure out the best way to send a bitmap to a webserver to store into a database. Right now, I am sending a string placeName to the server like this:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("mywebserver");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("placeName",placeName));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

This is successful. Now, basically what I want to do is something like this

Bitmap photo = (Bitmap) data.getExtras().get("data"); 
nameValuePairs.add(new BasicNameValuePair("placePhoto",photo));
//obviously pseudocode

Is there a way I can do this? Thanks.

user1282637
  • 1,827
  • 5
  • 27
  • 56

2 Answers2

0

1) In first side decode bitmap into byte array
2) In other side - create bitmap from byte array.

BitmapFactory documentation

Bitmap TO byte array

Bitmap FROM byte array

Community
  • 1
  • 1
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
0

You first have to convert the Bitmap to a byte array. And then Base64 encode the byte array to a String photoBase64; Then you can put it as name-value pair ("placePhoto", photoBase64). On the receiving side reverse.

How to do the conversions is easy to find on this site.

greenapps
  • 11,154
  • 2
  • 16
  • 19