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: 

Objective-C V2: downloadData and downloadUrl not working

Objective-C V2: downloadData and downloadUrl not working

pstoppani
Helpful | Level 5
Go to solution

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

1 Accepted Solution

Accepted Solutions

pstoppani
Helpful | Level 5
Go to solution
Ah, Podfile specified iOS plath '8.0' instead of '9.0'. That fixed the problem!

Thanks much 🙂

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution
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
Helpful | Level 5
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution
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

pstoppani
Helpful | Level 5
Go to solution
Ah, Podfile specified iOS plath '8.0' instead of '9.0'. That fixed the problem!

Thanks much 🙂
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    pstoppani Helpful | Level 5
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?