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

  • Home
  • SEARCH
  • 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 8538217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:05:28+00:00 2026-06-11T11:05:28+00:00

I have to get zip file from server to Android phone, encoded to Base64.

  • 0

I have to get zip file from server to Android phone, encoded to Base64. Because the file is large (~20MB) I am using below code for getting the String by bufferSize=1024*1024, encoding it and writing it to file.
I get bad-base64 error by the method android.util.Base64.encode(). Why?

The code:

int bufferSize = 1024 * 1024;
byte[] buffer = new byte[bufferSize];
FileOutputStream fileOutputStream = null;
InputStream inputStream = null;
try {
    fileOutputStream = new FileOutputStream(this.path + "/" + this.zipFileName);
    inputStream = connection.getInputStream();
    int bytesRead;
    //read bytes
    while ((bytesRead = inputStream.read(buffer, 0, bufferSize)) > 0) {
        byte[] zipBytes = Base64.decode(buffer, 0, bytesRead, Base64.DEFAULT);
        fileOutputStream.write(zipBytes);
    }
} catch (Exception e) {
e.printStackTrace();
} finally {
    if (fileOutputStream != null) {
        try {
        fileOutputStream.close();
        } catch (Exception e) {
        e.printStackTrace();
        }
    }
    if (inputStream != null) {
        try {
        inputStream.close();
            } catch (Exception e) {
        e.printStackTrace();
        }
    }
}
  • 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-11T11:05:29+00:00Added an answer on June 11, 2026 at 11:05 am

    First of all, why Base64? The usual thing to do would be to just send the zipped file and then let the client decompress it — it is going to save bandwidth since Base64 is limited to 6 bits per character. If you can change the server code it would be best to serve the zip file as is.

    Anyway, even if you get the file by chunks you cannot decode those chunks separately — you have to put all of the 1024*1024 bytes chunks together and then decode the lot. You need a 20MB buffer for this operation. Base64 adds some terminator characters to the end of each chunk. The wikipedia article has a quite good explanation.

    Another option would be make the chunk size a multiple of three; in this case I think that the Base64 result could be divided in chunks and be identical to the input. It is worth a try.

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

Sidebar

Related Questions

I have to get a date from a string. So I am using the
I want to download a file from server to a local host. i have
I'm trying to create a .zip file from an asset from another server like
I am downloading zip files from FTP server using PHP ftp function.I used binary
I have a web page hosted on the server and a zip file on
I want to save zip archive from server to user computer. I have web
I am trying to get the zip code of the users current location.I have
I have to get records from my MySQL DB where: sentto = $username OR
I have to get data from Oracle Table in which I have one datefield
i have to get static information from one 'module' to another. I'm trying to

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.