首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dropbox ChunkedUpload

Dropbox ChunkedUpload
EN

Stack Overflow用户
提问于 2012-11-01 15:59:43
回答 1查看 1.1K关注 0票数 1

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

以下代码将抛出该异常:

com.dropbox.client2.exception.DropboxIOException: Apache HTTPClient遇到一个错误。没有反应,再试一次。(在com.dropbox.client2.RESTUtility.execute(Unknown来源)在com.dropbox.client2.DropboxAPI$ChunkedUploadRequest.upload(Unknown来源)在com.dropbox.client2.DropboxAPI$ChunkedUploader.upload(Unknown来源)在com.dropbox.client2.DropboxAPI$ChunkedUploader.upload(Unknown来源)

以下是代码:

代码语言:javascript
复制
/** 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 :当然,我验证了传递给该方法的DropboxAPI实例是否符合其他api函数。

EN

回答 1

Stack Overflow用户

发布于 2012-11-28 18:15:07

我已将问题提交给Dropbox小组。他们只是回答我,那是Dropbox中的一个bug。1.5.3版本修复了它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13180853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档