4

I have searched the Dropbox documentation on its Developers page and on Stack Overflow, and I haven't found a way to get the upload progress of a file in the Java SDK for API v2. I don't have idea how to get the upload progress. Could someone help me with this?

I tried with ProgresMonitorInputStream, but it only tells me the progress of reading the file, it does not indicate the upload progress to the Dropbox server.

DbxRequestConfig config = DbxRequestConfig.newBuilder("My App/1.0.0").build();
DbxClientV2 client = new DbxClientV2(config, Constants.ACCESS_TOKEN);

    FileMetadata metadata;

    try {
        try (InputStream in = new FileInputStream(filepath)) {

            InputStream progressMonitorInputStream = new ProgressMonitorInputStream(null, "Uploading...", in);

            metadata = client.files()
                    .uploadBuilder("/test.exe")
                    .withMode(WriteMode.OVERWRITE)
                    .uploadAndFinish(progressMonitorInputStream);
        }

    } catch (DbxException | IOException e) {
        e.printStackTrace(System.err);
        return;
    }

I want the upload progress to show it in a JProgressBar.

4
  • [Cross-linking for reference: dropboxforum.com/t5/API-support/… ]
    – Greg
    Commented Jan 11, 2017 at 18:10
  • Have you found a solution on this :) ? I will be very glad to hear your news cause i need this also . I figured out how to get the progress of download but not for upload...
    – GOXR3PLUS
    Commented Nov 23, 2017 at 18:11
  • 1
    @GOXR3PLUS check main answer. Commented Dec 16, 2018 at 16:08
  • @CristiamMercado Gladddd so glad thank you :)
    – GOXR3PLUS
    Commented Dec 16, 2018 at 17:59

1 Answer 1

4

Greg K. from Dropbox team recently responded to this:

The Dropbox API v2 Java SDK now offers progress listeners for uploads and downloads. This has been released in v3.0.9:

https://github.com/dropbox/dropbox-sdk-java/releases/tag/v3.0.9

There's an example of using it with with the uploadAndFinish method (https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/DbxUploader.html#uploadAndFinish-java.io.InputStream-long-com.dropbox.core.util.IOUtil.ProgressListener-) for an upload here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/upload-file/src/main/java/com/dropbox/core/examples/upload_file/Main.java#L50

It works the same way with file downloads; the download method (https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/DbxDownloader.html#download-java.io.OutputStream-com.dropbox.core.util.IOUtil.ProgressListener-) optionally takes a ProgressListener parameter the same way.

[Cross-linking for reference: https://www.dropboxforum.com/t5/API-Support-Feedback/How-to-get-upload-progress-with-Java-SDK-v2/m-p/297837#M18078]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.