java - Dropbox 分块上传

标签 java dropbox dropbox-api

我正在尝试实现分块上传到 Dropbox。 我已经根据 Dropbox API 文档中的示例编写了代码,但失败了。

以下代码抛出该异常:

com.dropbox.client2.exception.DropboxIOException: Apache HTTPClient encountered an error. No response, try again. at com.dropbox.client2.RESTUtility.execute(Unknown Source) at com.dropbox.client2.DropboxAPI$ChunkedUploadRequest.upload(Unknown Source) at com.dropbox.client2.DropboxAPI$ChunkedUploader.upload(Unknown Source) at com.dropbox.client2.DropboxAPI$ChunkedUploader.upload(Unknown Source)

这是代码:

/** Uploads content to Dropbox.
 * @param dropbox An already linked dropbox API
 * @param stream The stream to upload
 * @param length The number of bytes to upload
 * @param path The path where to store the uploaded content
 * @return a boolean, false if the upload was cancelled, true if it completes 
 * @throws IOException
 * @throws DropboxException
 */
public static boolean upload(DropboxAPI<?> dropbox, InputStream stream,
        long length, String path) throws IOException, DropboxException {
    // Create a chunked uploader
    ChunkedUploader uploader = dropbox.getChunkedUploader(stream, length);
    try {
        int tryCounter = 1;
        while (!uploader.isComplete()) {
            try {
                uploader.upload(); // The exception occurs on this line
            } catch (DropboxException e) {
                tryCounter++;
                if (tryCounter > 5) throw e; // Give up after a while.
                System.err.println ("Upload failed, trying again ...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                }
            }
        }
    } catch (DropboxPartialFileException e) {
        // Upload was cancelled
        return false;
    }
    // If the upload completes, determine the current revision of the path.
    String parentRev = null;
    try {
        Entry metadata = dropbox.metadata(path, 1, null, false, null);
        parentRev = metadata.rev;
    } catch (DropboxServerException e) {
        // If the error is not a FileNotFound error => It's really an error
        if (e.error!=DropboxServerException._404_NOT_FOUND) throw e;
    }
    // Finish the upload
    uploader.finish(path, parentRev);
    return true;
}

知道我做错了什么吗?

PS:当然,我验证了其他 api 函数对于我传递给该方法的 DropboxAPI 实例是正常的。

最佳答案

我已将问题提交给 Dropbox 团队。 他们只是回答我这是 Dropbox API 中的一个错误。 1.5.3 版本修复了这个问题。

关于java - Dropbox 分块上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13180853/

相关文章:

java - 有没有错误?

java - 如何使用字符串键对 map 进行排序?像(1英尺,2英尺)

java - 无法预部署处于无效状态的 PersistenceUnit [PU] [DeployFailed]

svn - 将 Subversion 与 DropBox 结合使用

sqlite - 评估将 Core Data 与 Dropbox 同步的策略

javascript - 关于使用 Dropbox API 和 Javascript 访问文件的帮助

java - 与android线程相关的looper、handler等术语是什么?这些类之间有何关系?

bash - 程序化保管箱共享

c# - 将文件上传到保管箱中的特定文件夹

javascript - Dropbox API 文件 URL 无效