cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Download not able to find file when exists

Download not able to find file when exists

datan3rd
Explorer | Level 3
Go to solution

 

Building an app using xcode and objective c. I have been able to successfully get my backup sqlite file to upload but when attempting to use a download I am getting an error saying the file could not be opened because there is no such file. Am I missing something in the directory? I have tried all combinations including dropping the home/ and Apps/ and even the full web URL with no luck. The file exists when I access dropbox directly through the web.

DBUserClient *client = [DBClientsManager authorizedClient];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *outputDirectory = [fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
    NSURL *outputUrl = [outputDirectory URLByAppendingPathComponent:@"Backup.sqlite"];

    [[[client.filesRoutes downloadUrl:@"/home/Apps/Backup" overwrite:YES destination:outputUrl]
      setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *networkError,
                         NSURL *destination) {
          if (result) {
              NSLog(@"%@\n", result);
              NSData *data = [[NSFileManager defaultManager] contentsAtPath:[destination path]];
              NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
              NSLog(@"%@\n", dataStr);
          } else {
              NSLog(@"%@\n%@\n", routeError, networkError);
          }
      }] setProgressBlock:^(int64_t bytesDownloaded, int64_t totalBytesDownloaded, int64_t totalBytesExpectedToDownload) {
          NSLog(@"%lld\n%lld\n%lld\n", bytesDownloaded, totalBytesDownloaded, totalBytesExpectedToDownload);
      }];

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

I see, thanks for sharing the output. This error isn't actually reporting an issue with the remote path (indeed "/backups/mydatabase.sqlite" looks correct) but rather with the local path for the downloaded file. 

What version number of the SDK do you have installed? There were some bugs like this previously, but they should be resolved in the latest versions. If you're not already using the latest version (currently v.3.9.2) please update and try again.

View solution in original post

10 Replies 10

Pikamander2
Super User
Go to solution

Is the script able to download other files, like ones from other websites?

Aside from that, try some of the suggestions in this StackOverflow thread and see if they help.

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/53815606/objective-c-dropbox-sdk-v2-downloading-file-not-found ]

When referencing files by path using the Dropbox API, the path should be relative to whatever root your app has. For instance, if your app is registered for the "app folder" permission, its root is the app folder itself. That means you don't need to specify the path to the app folder, as that's handled automatically.

So, for instance, if you can see the file on the Dropbox web site under 'Apps > MyAppName > SomeFolderName > file.ext', to download that file via the API using your app folder app, you would supply just "/SomeFolderName/file.ext".

Preferrably though, you would just use the value supplied by the API itself. For instance, if you successfully upload a file, the upload method will return the metadata for the uploaded file. You can use the DBFILESMetadata.pathLower value directly as the path value elsewhere, such as when downloading the file again later.

datan3rd
Explorer | Level 3
Go to solution

Thanks for the reply Greg.

Right now when I upload I am getting the path_lower = /backups/mydatabase.sqlite and subsequently I am using the downloadUrl as /backups/mydatabase.sqlite

I have continuously been trying to tweak code to get it to work but that is where it is at right now and I am getting the following (slightly different from before but still not functioning):

DropboxClientError[{
    NSError = "Error Domain=NSCocoaErrorDomain Code=4 \"\U201cCFNetworkDownload_4Fyux0.tmp\U201d couldn\U2019t be moved to \U201cDocuments\U201d because either the former doesn\U2019t exist, or the folder containing the latter doesn\U2019t exist.\" UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/7EBD8463-4C04-4AA9-86C8-5D24280543F0/Library/Caches/com.apple.nsurlsessiond/Downloads/DataN3rd.mydatabase/CFNetworkDownload_4Fyux0.tmp, NSUserStringVariant=(\n    Move\n), NSDestinationFilePath=/var/mobile/Containers/Data/Application/7EBD8463-4C04-4AA9-86C8-5D24280543F0/Documents/mydatabase.sqlite, NSFilePath=/private/var/mobile/Containers/Data/Application/7EBD8463-4C04-4AA9-86C8-5D24280543F0/Library/Caches/com.apple.nsurlsessiond/Downloads/DataN3rd.mydatabase/CFNetworkDownload_4Fyux0.tmp, NSUnderlyingError=0x28367dda0 {Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"}}";

Greg-DB
Dropbox Staff
Go to solution

I see, thanks for sharing the output. This error isn't actually reporting an issue with the remote path (indeed "/backups/mydatabase.sqlite" looks correct) but rather with the local path for the downloaded file. 

What version number of the SDK do you have installed? There were some bugs like this previously, but they should be resolved in the latest versions. If you're not already using the latest version (currently v.3.9.2) please update and try again.

datan3rd
Explorer | Level 3
Go to solution

I am not sure what language that link is using but its not objective c. The script is a dropbox API call, not sure how or why it would point to other websites.

datan3rd
Explorer | Level 3
Go to solution

Greg. When I run pod update I can see I am on 3.0.15. How can I specify what version to update to? 

 

datan3rd
Explorer | Level 3
Go to solution

Ok. Found the issue witht the update. Pod file was specifying 8.0 not 9.0. Updated the SDK but now I am getting a build error on the download line:

No visible @interface for 'DBFILESUserAuthRoutes' declares the selector 'uploadData:mode:autorename:clientModified:mute:inputData:'

Greg-DB
Dropbox Staff
Go to solution

The method definition for uploadData has changed slightly since the old version you were using. You can find the current definitions here, but I recommend using Xcode's autocomplete to fill it for you.

datan3rd
Explorer | Level 3
Go to solution

How do I use xcodes autocomplete? I am not familiar with that.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    datan3rd Explorer | Level 3
What do Dropbox user levels mean?