download error: CFNetworkDownload_<some id>.tmp couldn't be moved to "" because an item with the same name already exists

download error: CFNetworkDownload_<some id>.tmp couldn't be moved to "" because an item with the same name already exists

我正在使用 ObjectiveDropbox 通过用户的 Dropbox 帐户管理一些任务,即列出文件和下载其中的一些文件。

列出我帐户中的文件和文件夹非常直接,但是当我想下载文件时,出现此错误: download error: CFNetworkDownload_<some id>.tmp couldn't be moved to <unique ID> because an item with the same name already exists.

知道为什么吗?

执行下载的代码:

        DropboxDownloadArg *downloadArg = [[DropboxDownloadArg alloc] initWithPath:metadata.pathLower];
NSURL *destURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]];
        [self.dropboxClient.files download:downloadArg
                       destFileUrl:destURL
                          progress:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {

                          } success:^(DropboxFileMetadata * _Nonnull metadata) {
                              [self.downloadDelegate downloadHasCompletedSuccessfully];
                          } fail:^(DropboxError * _Nonnull error) {
                              NSLog(@"download error: %@", error.errorSummary);
                              [self.downloadDelegate downloadFailed];
                          }];

我检查了 downloadArg 和 destURL 是否正确创建且有效。

谢谢

我刚刚重现了你的问题。看起来问题出在您的 destinationURL 中。 当您组合不同的路径并将它们从 NSURL 转换为 NSString 并返回时,您可以获得这样的路径:file:///file:/… 检查示例项目。它使用临时目录并且运行良好。

这里是 Documents 目录的工作代码:

NSURL *dir = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

NSURL *filePath = [dir URLByAppendingPathComponent:@"file.f"];

[self.dropbox.files download:downloadArg destFileUrl:filePath progress:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {