Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:25:31+00:00 2026-06-01T09:25:31+00:00

I am uploading image to server using base64 its working fine if image is

  • 0

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 {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        bitmap.recycle();
        byte[] byteArray = stream.toByteArray();
        stream.close();
        stream = null;
        String ba1 = Base64.encodeToString(byteArray, Base64.DEFAULT);

        bitmap = null;
        System.gc(); // immediately free bitmap

        byteArray = null;
        System.gc();
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(Data.upload_photo);

        JSONObject jsonObj = new JSONObject();
        jsonObj.put("user_id", LoginParser.id);
        int cnt = ba1.length() / 4;
        System.out.println("cnt=>" + cnt);
        jsonObj.put("image", ba1);

        jsonObj.put("caption", edt_caption.getText().toString());
        // Create the POST object and add the parameters

        /*
         * StringEntity entity = new StringEntity(jsonObj.toString(),
         * HTTP.UTF_8); System.out.println(entity);
         * entity.setContentType("application/json");
         * httppost.setEntity(entity);
         * 
         * HttpResponse response = httpclient.execute(httppost);
         */

        StringEntity se = new StringEntity(jsonObj.toString());
        // se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
        // "application/json"));
        se.setContentType("application/json");
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);

        String result = EntityUtils.toString(response.getEntity());
        System.out.println("=>=>" + result);
        JSONObject jsonObject = new JSONObject(result);
        if (jsonObject.getString("status").equals("success"))
            return "success";
        else
            return jsonObject.getString("message");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:25:33+00:00Added an answer on June 1, 2026 at 9:25 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently uploading an image to a server using Imgur on iOS with the
Greetings, I'm uploading an image to my server using the following code: http://cocoadev.com/index.pl?HTTPFileUploadSample However,
I am using MIME multipart for uploading images to server. Sometime image get distorted.
I am using asp.net fileupload control for uploading image but here i want to
In my application I'm uploading an image on to the server. Here in the
How should I handle image uploading using PHP? How should I handle the chmod
I have read the following tutorial Uploading Files To the Server Using PHP and
I have tried uploading a transparent PNG image to a SQL server image field,
I'm working on a project that involves uploading an image to tumblr from Python.
Very strange (to me) problem when uploading files to a server using ASIFormDataRequest. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.