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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:44:34+00:00 2026-06-01T00:44:34+00:00

There are several questions discussing ways in which progress indication can be added to

  • 0

There are several questions discussing ways in which progress indication can be added to HTTP file uploads in Android using the multipart/form-data data format. The typical approach suggested is epitomized by the top answer in Can't grab progress on http POST file upload (Android) — include the MultipartEntity class from the full Apache HTTPClient library, and then wrap the input stream it uses to get data in one that counts bytes as they’re read.

This approach works for this case, but unfortunately does not work for requests sending data via UrlEncodedFormEntity, which expects its data to be passed to it in Strings rather than InputStreams.

So my question is, what approaches are available to determine progress for uploads via this mechanism?

  • 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-01T00:44:35+00:00Added an answer on June 1, 2026 at 12:44 am

    You can override the #writeTo method of any HttpEntity implementation and count bytes as they get written to the output stream.

    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
       HttpPost httppost = new HttpPost("http://www.google.com/sorry");
    
       MultipartEntity outentity = new MultipartEntity() {
    
        @Override
        public void writeTo(final OutputStream outstream) throws IOException {
            super.writeTo(new CoutingOutputStream(outstream));
        }
    
       };
       outentity.addPart("stuff", new StringBody("Stuff"));
       httppost.setEntity(outentity);
    
       HttpResponse rsp = httpclient.execute(httppost);
       HttpEntity inentity = rsp.getEntity();
       EntityUtils.consume(inentity);
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
    
    static class CoutingOutputStream extends FilterOutputStream {
    
        CoutingOutputStream(final OutputStream out) {
            super(out);
        }
    
        @Override
        public void write(int b) throws IOException {
            out.write(b);
            System.out.println("Written 1 byte");
        }
    
        @Override
        public void write(byte[] b) throws IOException {
            out.write(b);
            System.out.println("Written " + b.length + " bytes");
        }
    
        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            out.write(b, off, len);
            System.out.println("Written " + len + " bytes");
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are several questions on StackOverflow discussing the question of when one should use
I know there are several questions similar, but I can't find one that answers
There have been several questions on SO regarding getting Contacts numbers using the Contacts
There are several questions on Stack Overflow discussing how to find the Greatest Common
There have been several questions already posted with specific questions about dependency injection ,
There have been several questions recently about database indexing and clustered indexing and it
There have been several questions posted to SO about floating-point representation. For example, the
There have been several questions over the past few days about the proper use
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
There are several topics about what questions will be raised in an interview for

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.