有没有办法使用Java将文件上传的进度条添加到dropbox

时间:2014-12-15 12:18:59

标签: java dropbox-api

我使用java将文件上传到dropbox。但问题是我如何添加进度条到文件上传到Dropbox。我没有使用java脚本。我没有在Dropbox API中获得任何此类功能。 我的代码是。

import com.dropbox.core.*;
import java.io.*;
import java.util.Locale;
public class Main {
public static void main(String[] args) throws IOException, DbxException {
    // Get your app key and secret from the Dropbox developers website.
    final String APP_KEY = "INSERT_APP_KEY";
    final String APP_SECRET = "INSERT_APP_SECRET";

    DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);

    DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
        Locale.getDefault().toString());
    DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);

    // Have the user sign in and authorize your app.
    String authorizeUrl = webAuth.start();
    System.out.println("1. Go to: " + authorizeUrl);
    System.out.println("2. Click \"Allow\" (you might have to log in first)");
    System.out.println("3. Copy the authorization code.");
    String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

    // This will fail if the user enters an invalid authorization code.
    DbxAuthFinish authFinish = webAuth.finish(code);
    String accessToken = authFinish.accessToken;

    DbxClient client = new DbxClient(config, accessToken);

    System.out.println("Linked account: " + client.getAccountInfo().displayName);

    File inputFile = new File("working-draft.txt");
    FileInputStream inputStream = new FileInputStream(inputFile);
    try {
        DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
            DbxWriteMode.add(), inputFile.length(), inputStream);
        System.out.println("Uploaded: " + uploadedFile.toString());
    } finally {
        inputStream.close();
    }

    DbxEntry.WithChildren listing = client.getMetadataWithChildren("/");
    System.out.println("Files in the root path:");
    for (DbxEntry child : listing.children) {
        System.out.println("    " + child.name + ": " + child.toString());
    }

    FileOutputStream outputStream = new FileOutputStream("magnum-opus.txt");
    try {
        DbxEntry.File downloadedFile = client.getFile("/magnum-opus.txt", null,
            outputStream);
        System.out.println("Metadata: " + downloadedFile.toString());
    } finally {
        outputStream.close();
    }
}

0 个答案:

没有答案