HttpPost httppost = new HttpPost("http://upload-test.php");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
HttpClient httpClient = new DefaultHttpClient();
if(bm!=null){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
ByteArrayBody bab = new ByteArrayBody(data, name+".jpg");
entity.addPart("file", bab);
}
try {
StringBody sname = new StringBody(name);
entity.addPart("name", sname);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
httppost.setEntity(entity);
try {
httpClient.execute(httppost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
In this example, when you send an image (jpg) and String, you can download a multi-page message library here: http://hc.apache.org/downloads.cgi
bm - bitmap. You can also use:
Bundle bundle=new Bundle();
bundle.putString("key", "value");
byte[] b = bundle.getByteArray("key");
ByteArrayBody bab = new ByteArrayBody(b,"info");
jsaye source
share