1

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

以下代码引发该异常:

com.dropbox.client2.exception.DropboxIOException:Apache HTTPClient 遇到错误。没有反应,再试一次。在 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(未知来源)

这是代码:

/** 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 实例没有问题。

4

1 回答 1

1

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

于 2012-11-28T18:15:07.757 回答