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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:07:03+00:00 2026-06-05T22:07:03+00:00

I have been using this code, but have been running into some memory issues:

  • 0

I have been using this code, but have been running into some memory issues:

      // Get the image from the sdcard
      Bitmap bm = BitmapFactory.decodeFile("/sdcard/myimage.jpg");
      // turn image into byte array output stream
      ByteArrayOutputStream baos = new ByteArrayOutputStream();  
      // 'compress' the jpeg
      bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);               
      // get byte[] array of the image        
      byte[] byteArray = baos.toByteArray();
      // turn image into base64 string        
      String encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
      // and base64 string to 'params' value pair        
      params.add(new BasicNameValuePair("userfile", encodedImage));

      try {
       HttpPost request = new HttpPost();

       String urlString = "http://www.example.com";
       request.setURI(new URI(urlString));

     if(params != null) {
        request.setEntity(new UrlEncodedFormEntity(params));
        HttpClient client = new DefaultHttpClient();
        client.execute(request);
     } // end if
} // end try

It has been suggested that I should use Base64OutputStream instead of Base64.encodeToString , but I have not been successful in using Base64OutputStream outputting a string that I can upload to the server. Any examples of using Base64OutputStream on an IMAGE would be a great help.

EDIT

To make the answer work, You need to add two files to your Android project: apache-mime4j-dom-0.7.2.jar and httpmime-4.1.3.jar;

You can download apache-mime4j-dom-0.7.2.jar from http://james.apache.org/download.cgi#Apache_Mime4J – download the binary, unzip it, and find the apache-mime4j-dom-0.7.2.jar file.

Then go to http://grepcode.com/snapshot/repo1.maven.org/maven2/org.apache.httpcomponents/httpmime/4.1.3 and download httpmime-4.1.3.jar

Then drag both those files into your project in Eclipse. Then in Eclipse, choose Project > Properties. Select the Properties Pop-up, select Java Build Path. Click the “Libraries” tab (Look for Source | Projects | Libraries | Order and Export). Click “Add Jars” and selectapache-mime4j-dom-0.7.2.jar and httpmime-4.1.3.jar; Then click the “Order and Export” tab. Check apache-mime4j-dom-0.7.2.jar and httpmime-4.1.3.jar; Then close that popup and choose Project > Clean from the Eclipse menu.

  • 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-05T22:07:05+00:00Added an answer on June 5, 2026 at 10:07 pm

    If possible, you should not base64encode your files and send them in URL, but use MultiPart file upload instead:

    HttpPost post = new HttpPost(URL);
    HttpClient client = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
    
    // picture
    entity.addPart( "userfile", new FileBody( 
        new File( MyApp.getContext().getFilesDir(), "userfile.jpg" ),
        "image/jpeg")
    );
    
    entity.addPart( "blahblah", new StringBody( "blah" ));  // string value
    
    post.setEntity( entity );
    client.execute( post );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Perl for some time, but today I came across this
I have been using this code with great success to pull out the first
I have been using this as a reference, but not able to accomplish exactly
So I've been running into some speed issues with my site which has been
I am using the Business Silverlight application. I have incorporated some MVVM into this
I have been using this copy method for quite a while, in lots of
I have been using this so far system 'strings binary-file.dmp | grep search_string' Is
I have been using this excellent decorator for memoization, which I found on the
[i meant to ask this question on StackOverflow...] I have been using VisualSVN Server
I have been trying to parse the bottom table on this site using different

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.