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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:36:50+00:00 2026-06-09T17:36:50+00:00

how can i get the percentage of upload completed and do a progress update

  • 0

how can i get the percentage of upload completed
and do a progress update to my progress bar.

I am adding my upload code.
I am using it in async task.

please help.
Thank you

ileInputStream fileInputStream = new FileInputStream(sourceFile);
                     URL url            =   new URL(upLoadServerUri);
                     conn               =   (HttpURLConnection) url.openConnection(); // Open a HTTP  connection to  the URL
                     conn.setDoInput(true); // Allow Inputs
                     conn.setDoOutput(true); // Allow Outputs
                     conn.setUseCaches(false); // Don't use a Cached Copy
                     conn.setRequestMethod("POST");
                     conn.setRequestProperty("Connection", "Keep-Alive");
                     conn.setRequestProperty("ENCTYPE", "multipart/form-data");
                     conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
                     conn.setRequestProperty("uploaded_file", fileName); 
                     dos        =   new DataOutputStream(conn.getOutputStream());

                     dos.writeBytes(twoHyphens + boundary + lineEnd); 
                     dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""+ fileName + "\"" + lineEnd);
                     dos.writeBytes(lineEnd);
                      Log.i("buffer", "jgf"+fileInputStream.read());


                     bytesAvailable = fileInputStream.available(); // create a buffer of  maximum size
                     bufferSize     = Math.min(bytesAvailable, maxBufferSize);
                     buffer         = new byte[bufferSize];

                     // read file and write it into form...
                     bytesRead      = fileInputStream.read(buffer, 0, bufferSize);  

                     while (bytesRead > 0) 
                     {
                       dos.write(buffer, 0, bufferSize);
                       bytesAvailable =     fileInputStream.available();
                       bufferSize     =     Math.min(bytesAvailable, maxBufferSize);
                       bytesRead      =     fileInputStream.read(buffer, 0, bufferSize);
}

dos.writeBytes(lineEnd);
                         dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

                     // Responses from the server (code and message)
                    serverResponseCode = conn.getResponseCode();
                    String serverResponseMessage    =   conn.getResponseMessage();

                     Log.i("uploadFile", "HTTP Response is : " + serverResponseMessage + ": " + serverResponseCode);

                     if(serverResponseCode == 200){
                         runOnUiThread(new Runnable() {
                              public void run() {

                                  Toast.makeText(getApplicationContext(), "File Upload Complete.", Toast.LENGTH_SHORT).show();                            
                                  dialog.dismiss();

                              }
                          });                
                     }    

                     //close the streams //
                     fileInputStream.close();
                     dos.flush();
                     dos.close();
  • 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-09T17:36:52+00:00Added an answer on June 9, 2026 at 5:36 pm

    You should make use of AsynchTask and its publishProgress(). You can find a lot of examples if you search around, for example this.

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

Sidebar

Related Questions

I am trying to get some percentage data from a stored procedure using code
How can i get the percentage of the changes which happened? Like 1. date
Can I get somehow(from a database or other source) a percentage of the phones
Possible Duplicate: CSS - percentage height I can't get the middle div of 3
You can get a list of databases using PRAGMA database_list or a list of
I am using the following code to show percentage using String.Format but I also
In MySQL, how can I compare two strings and get matching percentage. Something like
I want to find out if I can get some data on the percentage
How do I get data displayed as a percentage on hover? I can get
I would like to know how can I get the percentage value of a

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.