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

  • Home
  • SEARCH
  • 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 9031487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:44:39+00:00 2026-06-16T07:44:39+00:00

How to check the progress of an upload that use GoogleDrive API? The service.files().insert(body,

  • 0

How to check the progress of an upload that use GoogleDrive API?

The service.files().insert(body, mediaContent).execute(); only return a file which we can check if the file has upload completely.

But I need to check the progress in real time(at least each second or so), anyway to do it?

And for download part, I think we can manually compare how many bytes we have already read from the inputstream to the total filesize, then calculate the current progress.

But is this the correct way? Or there is other better way of checking progress?

private void saveFileToDrive() {
    Thread t = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          // File's binary content
          java.io.File fileContent = new java.io.File(fileUri.getPath());
          FileContent mediaContent = new FileContent("image/jpeg", fileContent);

          // File's metadata.
          File body = new File();
          body.setTitle(fileContent.getName());
          body.setMimeType("image/jpeg");

          File file = service.files().insert(body, mediaContent).execute();
          if (file != null) {
            showToast("Photo uploaded: " + file.getTitle());
            //startCameraIntent();
          }
        } catch (UserRecoverableAuthIOException e) {
          startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    });
    t.start();
  }

EDITED: Using this code http://code.google.com/p/google-api-java-client/source/browse/drive-cmdline-sample/src/main/java/com/google/api/services/samples/drive/cmdline/DriveSample.java?repo=samples&name=based-on-1.12&r=08555cd2a27be66dc97505e15c60853f47d84b5a

I am able to get some progress now if I am using resumable upload, I set chunksize to 1MB.
BUT there are 2 problems now.

1) The resumable upload is much slower than single upload, because it stop many times in between, only sending 1MB each time.
If I set chunksize to higher, then it wont show progress at all for smaller file.
So, progress in resumable upload is not what I actually want. I want progress in single upload.

2) If I set chunksize about 1MB, my upload always fail at about 70% for a normal 10MB file.
If I set chunksize to 10MB then it will success, but I wont see any progress.

Drive.Files.Insert insert = service.files().insert(body, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(10*1024*1024); // previously I am using 1000000 thats why it won't work
uploader.setProgressListener(new FileUploadProgressListener());
com.google.api.services.drive.model.File f = insert.execute();

LogCat Error:

11-27 19:23:26.927: D/FileUploadProgressListener(11527): Upload is In Progress: 0.5235538030501893
11-27 19:23:33.692: D/FileUploadProgressListener(11527): Upload is In Progress: 0.56095050326806
11-27 19:23:38.294: D/FileUploadProgressListener(11527): Upload is In Progress: 0.5983472034859306
11-27 19:23:50.583: D/FileUploadProgressListener(11527): Upload is In Progress: 0.6357439037038013
11-27 19:23:55.091: D/FileUploadProgressListener(11527): Upload is In Progress: 0.673140603921672
11-27 19:24:05.130: D/FileUploadProgressListener(11527): Upload is In Progress: 0.7105373041395426
11-27 19:24:17.005: D/FileUploadProgressListener(11527): Upload is In Progress: 0.7479340043574133
11-27 19:24:28.888: D/FileUploadProgressListener(11527): Upload is In Progress: 0.785330704575284
11-27 19:24:28.896: W/HttpTransport(11527): exception thrown while executing request
11-27 19:24:28.896: W/HttpTransport(11527): java.io.IOException: unexpected end of stream
11-27 19:24:28.896: W/HttpTransport(11527):     at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
11-27 19:24:28.896: W/HttpTransport(11527):     at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:88)
11-27 19:24:28.896: W/HttpTransport(11527):     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:980)
11-27 19:24:28.896: W/HttpTransport(11527):     at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:293)
11-27 19:24:28.896: W/HttpTransport(11527):     at com.google.api.services.drive.Drive$Files$Insert.executeUnparsed(Drive.java:309)
11-27 19:24:28.896: W/HttpTransport(11527):     at com.google.api.services.drive.Drive$Files$Insert.execute(Drive.java:331)
  • 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-16T07:44:40+00:00Added an answer on June 16, 2026 at 7:44 am

    Progress listener:

    private class FileUploadProgressListener implements MediaHttpUploaderProgressListener {
    
        private String mFileUploadedName;
    
        public FileUploadProgressListener(String fileName) {
            mFileUploadedName = fileName;
        }
    
        @Override
        public void progressChanged(MediaHttpUploader mediaHttpUploader) throws IOException {
            if (mediaHttpUploader == null) return;
            switch (mediaHttpUploader.getUploadState()) {
                case INITIATION_STARTED:
                //System.out.println("Initiation has started!");
                    break;
                case INITIATION_COMPLETE:
                //System.out.println("Initiation is complete!");
                    break;
                case MEDIA_IN_PROGRESS:
                    double percent = mediaHttpUploader.getProgress() * 100;
                    if (Ln.DEBUG) {
                        Log.d(Ln.TAG, "Upload to Dropbox: " + mFileUploadedName + " - " + String.valueOf(percent) + "%");
                    }
                    notif.setProgress(percent, mFileUploadedName).fire();
                    break;
                case MEDIA_COMPLETE:
                //System.out.println("Upload is complete!");
            }
        }
    }
    

    More information here:
    https://code.google.com/p/google-api-java-client/wiki/MediaUpload

    Direct media upload will upload the whole media content in one request as opposed to the resumable media upload protocol that could upload in multiple requests.

    Doing a direct upload reduces the number of HTTP requests but
    increases the change of failures with a large media upload (e.g.
    connection failure).

    Because of the architecture of the library, you have to choose between chunk and progress OR one step without progress.
    The smallest Chunk size should improve things.
    Smaller chunk possible:

    setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE)
    

    Hope it helps!

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

Sidebar

Related Questions

I'm using Amazon's provided High-Level API to upload files to Amazon S3. I use
Check the below code int add(int a, int b) { return a + b;
Check out this jsbin . I have a form with a custom button that
Check out http://fube.ca in any browser but Firefox and you'll see that the cloud
Objective : Make a progress bar where users can check how much of a
I'm trying to refresh the progress bar in an UIProgressView for an upload request
I've been trying to create a non-flash upload panel which also shows a progress
I got some question is using ASIHTTPRequest to tracking Upload/Download progress This is the
My application allows user to upload CSV file that is processed and records are
i'm trying to simply fill a progress bar, full when a check box is

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.