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 6991451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:30:14+00:00 2026-05-27T19:30:14+00:00

I’m trying to send data to a server. That is, some string fields and

  • 0

I’m trying to send data to a server. That is, some string fields and an image, which is encoded as base64 and passed as a String like this:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
        mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] byteArray = stream.toByteArray();
        //Cleaning memory
        try {
            stream.close();
            stream = null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //Eecode base64
        nameValuePairs.add(new BasicNameValuePair(DatosDB.KEY_IMG, Base64.encodeToString(byteArray, Base64.DEFAULT)));
        byteArray = null;

And then, when preparing the HTTP PUT request:

 try{
        HttpClient httpclient = new DefaultHttpClient();
        //PUT
        HttpPut httpput = new HttpPut(KEY_121 + ruta);
        //The exception is thrown when executing next instruction
        httpput.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httpput);

        HttpEntity entity = response.getEntity();
        is = entity.getContent();

        }catch(Exception e){
        Log.e(TAG, "Error in http connection "+e.toString());
        }   

The error looks like this:

12-20 00:24:11.622: ERROR/AndroidRuntime(7499): FATAL EXCEPTION: main
12-20 00:24:11.622: ERROR/AndroidRuntime(7499): java.lang.OutOfMemoryError
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:140)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at java.lang.StringBuilder.append(StringBuilder.java:125)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at java.net.URLEncoder.encode(URLEncoder.java:109)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at org.apache.http.client.utils.URLEncodedUtils.encode(URLEncodedUtils.java:184)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at org.apache.http.client.utils.URLEncodedUtils.format(URLEncodedUtils.java:163)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at org.apache.http.client.entity.UrlEncodedFormEntity.<init>(UrlEncodedFormEntity.java:71)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.upvar.Http_Request.put(Http_Request.java:171)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.upvar.Http_Request.poi(Http_Request.java:108)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.upvar.NewPOI.putPOI(NewPOI.java:360)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.upvar.NewPOI.access$6(NewPOI.java:325)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.upvar.NewPOI$5.onClick(NewPOI.java:157)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at android.view.View.performClick(View.java:2538)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at android.view.View$PerformClick.run(View.java:9152)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at android.os.Handler.handleCallback(Handler.java:587)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at android.os.Looper.loop(Looper.java:130)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at android.app.ActivityThread.main(ActivityThread.java:3687)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at java.lang.reflect.Method.invokeNative(Native Method)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at java.lang.reflect.Method.invoke(Method.java:507)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-20 00:24:11.622: ERROR/AndroidRuntime(7499):     at dalvik.system.NativeStart.main(Native Method)
12-20 00:24:11.632: WARN/ActivityManager(3923):   Force finishing activity com.android.upvar/.NewPOI
12-20 00:24:11.636: ERROR/(3923): Dumpstate > /data/log/dumpstate_app_error

I don’t see why am I getting this exception. I’m just sending a regular image that was taken from a Samsung Galaxay camera (for sure less than 16MB). Any idea?

EDIT: I must add, that the first chunk of code and the second one are on different classes, so the data on the first chunk of code is passed to an object of another class, which passes it to another object of another class, which has the HTTP request.

  • 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-05-27T19:30:15+00:00Added an answer on May 27, 2026 at 7:30 pm

    At the end, te solution was to compress the image to 50% as follows:

    mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    

    It reduces the image size and makes it small enough to send it as a String.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.