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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:05:13+00:00 2026-05-25T14:05:13+00:00

Im trying to stream a file from android to an asp.net service: private static

  • 0

Im trying to stream a file from android to an asp.net service:

private static void writeFile(File file, DataOutputStream out)
        throws IOException {

    BufferedInputStream bufferedFileIs = null;
    Base64OutputStream base64out = null;
    try {
        out.writeBytes("fileBase64=");
        base64out = new Base64OutputStream(out, Base64.DEFAULT);

        FileInputStream fileIs = new FileInputStream(file);
        bufferedFileIs = new BufferedInputStream(fileIs);
        int nextByte;
        while ((nextByte = bufferedFileIs.read()) != -1) {
            base64out.write(nextByte);
        }
    } finally {
        if (bufferedFileIs != null) {   
            bufferedFileIs.close();
        }
        if(base64out != null)
            base64out.flush();

    }

}

and receive it like this

String base64 = Request.Form["fileBase64"];

byte[] bytes = System.Convert.FromBase64String(base64);

I use an HttpURLConnection and I dont get any exceptions but the received file(image) is corrupted in the process.
I tried ALOT of different stream wrapper pairs, but no luck. Anyone have experience in this?
I stream other form entries in the same connection and these arrive un-corrupted, for example

&UserID=12345

Gratefull for your help.

Cheers!

  • 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-25T14:05:14+00:00Added an answer on May 25, 2026 at 2:05 pm

    Solved it:

    Prepare the file:

    File file = new File(LocalFilePath);
    
    FileEntity fileentity = new FileEntity(file, "UTF-8");
    HttpUtilities.postRequest(WebServiceURL, fileentity);
    

    post the request:

    public static String postRequest(String url, HttpEntity aEntity)
            throws IOException {
    
        InputStream is = null;
        try {
    
            HttpClient client = new DefaultHttpClient();
    
            HttpPost httppost = new HttpPost(url);
    
            httppost.setEntity(aEntity);
    
            HttpResponse response = client.execute(httppost);
            HttpEntity responseEntity = response.getEntity();
    
            is = responseEntity.getContent();
    
        } catch (Exception e) {
        }
    
        return getResponse(is);
    }
    

    after this the webserver complained:

    HttpException (0x80004005): Maximum request length exceeded
    

    max request-length defaults to 4mb so i set this in web.config:

    <system.web>
        <httpRuntime maxRequestLength="1048576"/>
    </system.web
    

    Which allows files up to 1GB(!).

    edit:

    Forgot the server code:

    var str = Request.InputStream;
    strLen = Convert.ToInt32(str.Length);
    byte[] strArr = new byte[strLen];
    strRead = str.Read(strArr, 0, strLen);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
So, I'm trying to use ADO.NET to stream a file data stored in an
I am trying to send data from an Android app to a PHP file
I'm trying to parse a file from the web on Android using the DOM
I'm trying to stream an audio file from a server protected by session-based authentication,
I am trying to stream/pipe a file to the user's browser through HTTP from
I'm trying to stream an audio file from a grails app. The audio file
I'm trying to stream the file from file system to browser and cant get
I am trying to stream files from a zip file using ZipEntry class in
I'm trying to upload a file from Android (2.3.4) using the below code, 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.