You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

datan3rd's avatar
datan3rd
Explorer | Level 3
7 years ago

Download not able to find file when exists

 

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

 

  • Greg-DB's avatar
    Greg-DB
    7 years ago

    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's avatar
      datan3rd
      Explorer | Level 3

      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.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    [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's avatar
      datan3rd
      Explorer | Level 3

      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's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        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.