Forum Discussion

datan3rd's avatar
datan3rd
Explorer | Level 3
8 years ago
Solved

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
    8 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.

10 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    [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
    8 years ago

    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 Community Moderator rankDropbox Community Moderator
    8 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
    8 years ago

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

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

    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's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

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

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

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    It should show up automatically when you're typing code. If you don't have it enabled, you can enable it under 'Preferences > Text Editing > Code completion'.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!