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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:24:44+00:00 2026-06-17T06:24:44+00:00

I have a ASP.Net web api which is intended to send a new file

  • 0

I have a ASP.Net web api which is intended to send a new file over the internet encoded as Base64. To do so, I have a public exposed REST service:

    string imei = ControllerContext.Request.Headers.GetValues("IMEI").FirstOrDefault();
    byte[] FileAsBytes = null;
    String base64 = null;
    var svcs = new CrudService.CrudServiceClient();

    if (svcs.IsDeviceAccepted(imei))
    {
        FileAsBytes = svcs.DownloadSoftwareVersion();
    }

    if(FileAsBytes != null)
    {
         base64 = Convert.ToBase64String(FileAsBytes);
    }

    return base64;

and a Private service, CRUD service, which communicates directly with the database and the core layers.

After some debugging I found out that this service returns the correct lenght, something like 4194304 bytes, which seems to correspond to the size of file. However on the client side, I am contacting this service inside a AsyncTask:

    @Override
    protected String doInBackground(String... params) {
        Log.i("UpdateManager: ", "Inside doInBackground");

        try {

            String imei = params[0];
            String urlString = "http://10.118.18.50/Mobile.RESTPublicService/api/SoftwareUpdate";

            HttpPost post = new HttpPost(urlString);
            post.addHeader("IMEI", imei);
            response = httpClient.execute(post);

            Log.w("Update-Response: ",
                    Integer.toString(response.getStatusLine().getStatusCode())
                            + " " + response.getStatusLine());

            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

                is = response.getEntity().getContent();
                IOUtils.copy(is, writer, "UTF-8");

                _log.debug(writer.toString());

                Log.w("CONTENT: ", writer.toString());
                byte[] result = new byte[MAX_FILE_SIZE]; //7242880 b
                result = decodeBase64(writer.toString());

                Log.w("BYTE ARRAY LENGTH: ", Integer.toString(result.length));

            }

        } catch (ClientProtocolException e) {
            Log.e("Client: ", e.getMessage());
            _log.error(e.getMessage());
            return FAILED_DUE_TO_EXCEPTION;
        } catch (IOException e) {
            Log.e("IO: ", e.getMessage());
            _log.error(e.getMessage());
            return FAILED_DUE_TO_EXCEPTION;
        }
        return response.getStatusLine().toString();
    }

The interesting point here is the result = decodeBase64(writer.toString()); and the decodeBase64 method:

protected byte[] decodeBase64(String s) {
        return Base64.decode(s);
    }

The String s is what I get from the webservice:

UEsDBBQACAgIAJteK0IAAAAAAAAAAAAAAAAZAAQAcmVzL2FuaW0vYWN0aXZpdHlmYWRlLnhtbP7KAABdkN9OwjAchc+PbW4YErnwgkRuuSGEek1MDI/SsMkmbF26es8D+AA+hs+hD6Wn0GXKab60/fq/ETK8CyCY4xNgL4TuCUPuyANZkEeyIXvySiaTqnGFbc1RO2MxHr9YU2+PbamRps5cWlmWv1ntKtNQ6ia3psqxXJbOtRul

This is not the whole file, but I can see that this is base64 encoded

When this string is passed inti the decodeBase64 method I only get this error message:

enter image description here

Then the application terminates. Is this the way to handle Base64 String? Can someone suggest how I can create a file from this base64 string? My first thought was to convert it to a byte array, and then create a file.

  • 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-17T06:24:45+00:00Added an answer on June 17, 2026 at 6:24 am

    Looks to me like you’ve got a quoted string there – because " is what seems to be making it blow up. Is the web service returning a JSON string? If it is, then it will be surrounded by quotes and you have to take those off in order to parse it from base 64.

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

Sidebar

Related Questions

I have an ASP.NET MVC 4 application which uses the new ASP.NET Web API.
I have the following action in my ASP.NET Web API: public IEnumerable<Car> carssOfUser(int id,
We have an ASP.NET Web API app which uses Ninject for DI. This works
I have an asp.net web api application which is acting as a Relay to
I have an ASP.NET 4.0 web application which uses a third-party API for external
I have developed an ASP.NET Web API which response like this: <ArrayOfMyData> <MyData> <Id>1</Id>
Suppose I have a ASP.NET Web API controller that uses a service, which in
I'm playing with ASP.NET Web API and I have the following: public Guid GetLogon(string
I am new to ASP.Net MVC and ASP.Net web api. I have worked on
We currently have a classic ASP.NET web application which serves as our API. It

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.