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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:08:45+00:00 2026-06-01T20:08:45+00:00

I want to show progress bar while uploading a video from my app to

  • 0

I want to show progress bar while uploading a video from my app to php server.The below will upload the file to the server correctly.But i dont know how to show the progress bar.If anybody knows pls help me.

Here is my code:

 private void doFileUpload(){
            HttpURLConnection conn = null;
            DataOutputStream dos = null;
            DataInputStream inStream = null;
            String lineEnd = "\r\n";
            String twoHyphens = "--";
            String boundary =  "*****";
            int bytesRead, bytesAvailable, bufferSize;
            byte[] buffer;
            int maxBufferSize = 8*1024*1024;
            Cursor c = (MainscreenActivity.JEEMAHWDroidDB).query((MainscreenActivity.TABLE_Name), new String[] {
                     (MainscreenActivity.COL_HwdXml)}, null, null, null, null,
                              null);
             if(c.getCount()!=0){
             c.moveToLast();
             for(int i=c.getCount()-1; i>=0; i--) {
                  value=c.getString(0);           
             }
             }
            String urlString = value+"/upload_file.php";
            try
            {
             //------------------ CLIENT REQUEST
                UUID uniqueKey = UUID.randomUUID();
                fname = uniqueKey.toString();
                Log.e("UNIQUE NAME",fname);

            FileInputStream fileInputStream = new FileInputStream(new File(selectedPath) );
            URL url = new URL(urlString);
            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
            dos = new DataOutputStream( conn.getOutputStream() );
             dos.writeBytes(twoHyphens + boundary + lineEnd);
             dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + fname + "."+extension+"" + lineEnd);
             dos.writeBytes(lineEnd);
             bytesAvailable = fileInputStream.available();
             System.out.println("BYTES:--------->"+bytesAvailable);
             bufferSize = Math.min(bytesAvailable, maxBufferSize);
             System.out.println("BUFFER SIZE:--------->"+bufferSize);
             buffer = new byte[bufferSize];
             System.out.println("BUFFER:--------->"+buffer);
             bytesRead = fileInputStream.read(buffer,0,bufferSize);
             System.out.println("BYTES READ:--------->"+bytesRead);
             while (bytesRead > 0)
             {
              dos.write(buffer, 0, bufferSize);
              bytesAvailable = fileInputStream.available();
              bufferSize = Math.min(bytesAvailable, maxBufferSize);
              bytesRead = fileInputStream.read(buffer, 0, bufferSize);
              System.out.println("RETURNED");
             }
             dos.writeBytes(lineEnd);
             dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

             Log.e("Debug","File is written");
             fileInputStream.close();
             dos.flush();
             dos.close();

            }
            catch (MalformedURLException ex)
            {
                 Log.e("Debug", "error: " + ex.getMessage(), ex);
            }
            catch (IOException ioe)
            {
                 Log.e("Debug", "error: " + ioe.getMessage(), ioe);
            }
            //------------------ read the SERVER RESPONSE
            try {
                  inStream = new DataInputStream ( conn.getInputStream() );
                  String str;

                  while (( str = inStream.readLine()) != null)
                  {
                       Log.e("Debug","Server Response "+str);
                  }
                  inStream.close();

            }
            catch (IOException ioex){
             Log.e("Debug", "error: " + ioex.getMessage(), ioex);
            }
  • 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-01T20:08:46+00:00Added an answer on June 1, 2026 at 8:08 pm

    Call new loadVideo().execute(); where ever you needed.
    And add the following class to do the video loading.

    public class loadVideo extends AsyncTask<Void, Void, Void>
        {
    
            private final ProgressDialog dialog = new ProgressDialog(
                    YourActivity.this);
            protected void onPreExecute() {
                this.dialog.setMessage("Loading...");
                this.dialog.setCancelable(false);
                this.dialog.show();
            }
            protected void onPostExecute(Void result) {
    
                if (this.dialog.isShowing()) {
                    this.dialog.dismiss();
                }
    
                    }
                });
    
    
    
            }
    
            @Override
            protected Void doInBackground(Void... params) {
     HttpURLConnection conn = null;
                DataOutputStream dos = null;
                DataInputStream inStream = null;
                String lineEnd = "\r\n";
                String twoHyphens = "--";
                String boundary =  "*****";
                int bytesRead, bytesAvailable, bufferSize;
                byte[] buffer;
                int maxBufferSize = 8*1024*1024;
                Cursor c = (MainscreenActivity.JEEMAHWDroidDB).query((MainscreenActivity.TABLE_Name), new String[] {
                         (MainscreenActivity.COL_HwdXml)}, null, null, null, null,
                                  null);
                 if(c.getCount()!=0){
                 c.moveToLast();
                 for(int i=c.getCount()-1; i>=0; i--) {
                      value=c.getString(0);           
                 }
                 }
                String urlString = value+"/upload_file.php";
                try
                {
                 //------------------ CLIENT REQUEST
                    UUID uniqueKey = UUID.randomUUID();
                    fname = uniqueKey.toString();
                    Log.e("UNIQUE NAME",fname);
    
                FileInputStream fileInputStream = new FileInputStream(new File(selectedPath) );
                URL url = new URL(urlString);
                conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
                dos = new DataOutputStream( conn.getOutputStream() );
                 dos.writeBytes(twoHyphens + boundary + lineEnd);
                 dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + fname + "."+extension+"" + lineEnd);
                 dos.writeBytes(lineEnd);
                 bytesAvailable = fileInputStream.available();
                 System.out.println("BYTES:--------->"+bytesAvailable);
                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
                 System.out.println("BUFFER SIZE:--------->"+bufferSize);
                 buffer = new byte[bufferSize];
                 System.out.println("BUFFER:--------->"+buffer);
                 bytesRead = fileInputStream.read(buffer,0,bufferSize);
                 System.out.println("BYTES READ:--------->"+bytesRead);
                 while (bytesRead > 0)
                 {
                  dos.write(buffer, 0, bufferSize);
                  bytesAvailable = fileInputStream.available();
                  bufferSize = Math.min(bytesAvailable, maxBufferSize);
                  bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                  System.out.println("RETURNED");
                 }
                 dos.writeBytes(lineEnd);
                 dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
    
                 Log.e("Debug","File is written");
                 fileInputStream.close();
                 dos.flush();
                 dos.close();
    
                }
                catch (MalformedURLException ex)
                {
                     Log.e("Debug", "error: " + ex.getMessage(), ex);
                }
                catch (IOException ioe)
                {
                     Log.e("Debug", "error: " + ioe.getMessage(), ioe);
                }
                //------------------ read the SERVER RESPONSE
                try {
                      inStream = new DataInputStream ( conn.getInputStream() );
                      String str;
    
                      while (( str = inStream.readLine()) != null)
                      {
                           Log.e("Debug","Server Response "+str);
                      }
                      inStream.close();
    
                }
                catch (IOException ioex){
                 Log.e("Debug", "error: " + ioex.getMessage(), ioex);
                }
    
                return null;
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show a progress bar while my iPhone app is uploading an
I want to show a progress bar while downloading a file from the web
In my project i want to show the progress bar while uploading files. I
I want to show upload progress bar for my uploads using servlet. I tried
I want to show up an progress bar while a download with NSURLConnection is
I'm uploading image files from device to a PHP server by converting the file
i want to show the progress of copying the file from one folder to
I want to show progress with jquery ui progress bar when an ajax request
I want to display a progress bar while doing some work, but that would
I have a Android application and I want to show a progress bar 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.