我需要在窗口(JFrame
)上显示当前正在上传到Dropbox的文件的上传进度。
我查看了多个示例,其中大多数都使用了dropbox API v1。
我需要使用API v2显示上传文件到Dropbox的进度。
我用于上传文件的编码如下所示: (我如何操纵它来显示文件上传进度。)
try
{
File file = new File("C:\\... Storage location of file on local system");
//reads file as input for the method to dropbox
InputStream fileupload = new FileInputStream(file);
//path in dropbox account to store the file
// if want to store it in root just put '/'
//if want to store file in a folder '/foldername/'
client.files().uploadBuilder("/" + file.getName())
.withMode(WriteMode.OVERWRITE)//always overwrites the existing file in the dropbox folder
.uploadAndFinish(fileupload);
JOptionPane.showMessageDialog(null, "File uploaded to dropbox");
}
//exception handled
catch (DbxException e)
{
//error message for uploading file to dropboxcloud
JOptionPane.showMessageDialog(null, "Unable to upload file to Cloud \n Error: " + e);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, "Unable to upload file to cloud \n Error: " + e);
}
在文件上传时,有人可以帮我解决这个进展吗?
答案 0 :(得分:0)
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.