0% found this document useful (0 votes)
15 views

Bit Map

This code sample shows how to upload an image file from an Android application to a web server using HTTP. It first encodes a bitmap image as a byte array, then encodes that array to Base64 format. It adds the Base64 encoded string as a parameter to an HTTP POST request, along with other parameters. It sends the request to a PHP file on a local web server and receives the response, storing the input stream for further processing.

Uploaded by

Hina Shahid
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Bit Map

This code sample shows how to upload an image file from an Android application to a web server using HTTP. It first encodes a bitmap image as a byte array, then encodes that array to Base64 format. It adds the Base64 encoded string as a parameter to an HTTP POST request, along with other parameters. It sends the request to a PHP file on a local web server and receives the response, storing the input stream for further processing.

Uploaded by

Hina Shahid
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

public class upload extends Activity { InputStream is; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.

main); Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.a1); ByteArrayOutputStream bao = new ByteArrayOutputStream(); bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao); byte [] ba = bao.toByteArray(); String ba1=Base64.encodeBytes(ba); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("image",ba1)); try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2:80/android/base.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); } } }

You might also like