Forum Discussion

pstoppani's avatar
pstoppani
Helpful | Level 5
8 years ago
Solved

Objective-C V2: downloadData and downloadUrl not working

I've got upload and listFolder working fine but just can't seem to get download to work.  If I use downloadData, it succeeds but the fileContents NSData is 'nil'!  

 

Code:

    [[[[self client].filesRoutes downloadData:@"/hello.txt"]
      setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *networkError, NSData *fileContents) {
          if (result) {
              NSLog(@"%@\n", result);
              [[Common sharedInstance].fileMgr removeItemAtPath:localPath error:nil];
              if (!fileContents) {
                  NSLog(@"fileContents == nil!");
              }
              else if ([[Common sharedInstance].fileMgr createFileAtPath:localPath contents:fileContents attributes:nil]) {
                  NSLog(@"%@ created\n", localPath);
              } else {
                  NSLog(@"%@ failed to create\n", localPath);
              }
          } else {
              NSLog(@"DropBoxDataItem -loadFileToPath %@ failed: %@/%@", localPath, routeError, networkError);
          }
      }] setProgressBlock:^(int64_t bytesDownloaded, int64_t totalBytesDownloaded, int64_t totalBytesExpectedToDownload) {
          NSLog(@"totalBytesDownloaded:%lld totalBytesExpectedToDownload:%lld\n", totalBytesDownloaded, totalBytesExpectedToDownload);
      }];

 

Test File:

1. hello
2. world

Console:

2017-09-27 18:25:41.468625-0700 neuNotesPlus[2600:1733011] totalBytesDownloaded:17 totalBytesExpectedToDownload:17
2017-09-27 18:25:41.482683-0700 neuNotesPlus[2600:1733011] {
    "client_modified" = "2017-09-28T00:39:54Z";
    "content_hash" = e50df240374d9d527244061aadc6196eef6255feab9b3ebb8e694ed65ee9de1e;
    id = "id:4VBVv54JdnsAAAAAAABN6A";
    name = "hello.txt";
    "path_display" = "/hello.txt";
    "path_lower" = "/hello.txt";
    rev = 927a05d7ff5b;
    "server_modified" = "2017-09-28T00:41:45Z";
    size = 17;
}
2017-09-27 18:25:41.483193-0700 neuNotesPlus[2600:1733011] fileContents == nil!

Clearly the file was downloaded per the progress block's NSLog.  Yet, the fileContents is nil!?

 

If I try to use downloadUrl, I get the following error:

2017-09-27 18:30:11.033183-0700 neuNotesPlus[2604:1734708] local folder exists: /private/var/mobile/Containers/Data/Application/FF881223-E369-4D28-908A-01768DB2D078/tmp
2017-09-27 18:30:11.801532-0700 neuNotesPlus[2604:1734708] totalBytesDownloaded:17 totalBytesExpectedToDownload:17
2017-09-27 18:30:11.826146-0700 neuNotesPlus[2604:1734708] DropBoxDataItem -loadFileToPath /private/var/mobile/Containers/Data/Application/FF881223-E369-4D28-908A-01768DB2D078/tmp/d2.neunote failed: (null)/DropboxClientError[{
    NSError = "Error Domain=NSCocoaErrorDomain Code=4 \"\U201cCFNetworkDownload_qZi9PJ.tmp\U201d couldn\U2019t be moved to \U201ctmp\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/FF881223-E369-4D28-908A-01768DB2D078/Library/Caches/com.apple.nsurlsessiond/Downloads/com.neupen.neuNotesPlus/CFNetworkDownload_qZi9PJ.tmp, NSUserStringVariant=(\n    Move\n), NSDestinationFilePath=/private/var/mobile/Containers/Data/Application/FF881223-E369-4D28-908A-01768DB2D078/tmp/d2.neunote, NSFilePath=/private/var/mobile/Containers/Data/Application/FF881223-E369-4D28-908A-01768DB2D078/Library/Caches/com.apple.nsurlsessiond/Downloads/com.neupen.neuNotesPlus/CFNetworkDownload_qZi9PJ.tmp, NSUnderlyingError=0x1c4440330 {Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"}}";
}];

The output 'tmp' folder exists so the problem must be in the temp file where the SDK initially downloaded the data.  Given my experience using downloadData, I'm not surprised there is something wrong with the temp file.

 

What could be causing these issues with just downloading?

 

Thx,

Pete

  • Ah, Podfile specified iOS plath '8.0' instead of '9.0'. That fixed the problem!

    Thanks much :)
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    Hi Pete, I just tried your code (commenting out the 'Common', etc. lines) and it worked correctly for me. I.e., fileContents wasn't nil.

    What version of the SDK do you have installed? There was a bug like this in an older version. If you don't have the latest version, currently 3.3.2, please update to that and let me know if you're still seeing this issue. Thanks!
    • pstoppani's avatar
      pstoppani
      Helpful | Level 5

      Hmm, 'pod' shows 'Using ObjectiveDropboxOfficial (3.0.15)'.  Now the question is why pod doesn't update to the latest?

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 2 days ago
351 Following

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 or Facebook.

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!