cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
In need of some #MondayMotivation? Read more

Objective-C V2: downloadData and downloadUrl not working

SOLVED
362 Views
4 Comments
0 Kudos
Highlighted
Level 5

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-28T0smiling face with halo9: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

1 Accepted solution

Accepted Solutions
Solution
Level 5

Re: Objective-C V2: downloadData and downloadUrl not working

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

Thanks much slightly smiling face
4 Replies
Dropboxer

Re: Objective-C V2: downloadData and downloadUrl not working

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!
Level 5

Re: Objective-C V2: downloadData and downloadUrl not working

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

Dropboxer

Re: Objective-C V2: downloadData and downloadUrl not working

You'll need to run `pod update` to update your pods. Also make sure your Podfile looks like the example (and isn't locked to a specific version) in order to make sure `pod update` will give you the latest version:

https://github.com/dropbox/dropbox-sdk-obj-c#cocoapods
Solution
Level 5

Re: Objective-C V2: downloadData and downloadUrl not working

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

Thanks much slightly smiling face