Android upload image to server using base64

后端 未结 1 1459
温柔的废话
温柔的废话 2020-12-06 15:38

I am uploading image to server using base64 its working fine if image is small but if image is big it gives me memory out exception

try {
        ByteArrayO         


        
1条回答
  •  鱼传尺愫
    2020-12-06 16:27

    Try this code once.

    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    bm.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("URL STRING");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        //Toast.makeText(SignUpActivity.this, "Joining Failed", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection " + e.toString());
    }
    

    I can help you if you have any doubt.

    0 讨论(0)
提交回复
热议问题