invalidArgument invalidArgument - 3 months ago 30
iOS Question

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

I'm using ObjectiveDropbox to manage some tasks with the user's Dropbox account, namely listing files and downloading some of them.

Listing the files and folders from my account is pretty straigt-forward, but when I want to download a file, I get this error:

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


Any idea why?

Code that does the download:

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];
}];


I checked that the downloadArg and the destURL are correctly created and valid.

Thank you

Answer

I have just reproduced your problem. Looks like the problem is in your destinationURL. When you combine different paths and convert them from NSURL to NSString and back you can get the path like this: file:///file:/… Check the example project. It uses temporary dir and it works well.

Here is the working code with Documents directory:

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) {