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.
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: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/mp/297837#M18078]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.