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

billymeltdown's avatar
billymeltdown
Explorer | Level 4
9 years ago

Getting rev from DBFILESMetadata in obj-c API 2

Dear Dropbox,

 

Thanks for the new obj-c API v2, looks like quite an effort! So far it's more convenient to use than API v1 and integration is going well. However, I'm a little held up on how to work with the response objects, I'm constantly looking for methods and properties on them that don't seem to be there and I think I'm misunderstanding how the union and struct object types work, the response and error objects. Here's a small example: I'm checking that a file exists, and in API v1 I hung on to the `rev` of the file, so that after I download it and modify it, I want to push it back up, and I need the rev on upload to do that without creating a new file/conflict.

 

According to this thread you can get the rev from the DBFILESMetadata response object in API 2:

https://www.dropboxforum.com/t5/API-support/Using-file-revs-in-API-2/m-p/191299#M8348

 

> In API 2, DBFILESFileMetadata has an equivalent .rev property - so far, so good.

 

But I'm pretty baffled as to where/how, I don't see it any such property listed for that object in the docs:

 

https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESMetadata.html

 

Here's a simple request that I think helps lay out where I'm getting confused:

 

[[client.filesRoutes getMetadata:path] response:^(DBFILESMetadata * _Nullable result, DBFILESGetMetadataError * _Nullable routeError, DBError * _Nullable error) {
    if (result != nil) {
        // File exists at that path
        self.foundFile = YES;
        // save the file rev
        self.dropboxFileRevsion = ... ?
    } else {
        self.foundDatabaseFile = NO;
        // But how do I check DBFILESGetMetadataError correctly for this request
        // to see if it's file not found—or some other error? I can't tell from
        // docs just yet
        if (routError != nil) {
        	// the only property on routeError that seems to relate is path...
        }
    }
    [self doNextThing];
}];

Thanks for your time! 

  • In your example, you would get it like this:

     

    self.dropboxFileRevision = ([result isKindOfClass:[DBFILESFileMetadata class]] ? [(DBFILESFileMetadata *)result rev] : nil);

     

    DBFILESFileMetadata is a subclass of DBFILESMetadata. Basically (as I understand it), you’ll never receive a vanilla DBFILESMetadata object in a response, but will receive one of its subclasses - DBFILESFolderMetadata, DBFILESFileMetadata or DBFILESDeletedMetadata. So you need to check the class of the meta-data object to see what you can extract from it. (I wrote a category so that I can call -isDirectory, -isFile or -isDeleted on the meta-data object rather than have to write out -isKindOfClass: each time.)

     

    (I’ve been getting to grips with the new API msyelf over the past few days, and the above comes from hounding Greg at Dropbox with questions. :) )

  • Keith B.7's avatar
    Keith B.7
    Helpful | Level 7

    In your example, you would get it like this:

     

    self.dropboxFileRevision = ([result isKindOfClass:[DBFILESFileMetadata class]] ? [(DBFILESFileMetadata *)result rev] : nil);

     

    DBFILESFileMetadata is a subclass of DBFILESMetadata. Basically (as I understand it), you’ll never receive a vanilla DBFILESMetadata object in a response, but will receive one of its subclasses - DBFILESFolderMetadata, DBFILESFileMetadata or DBFILESDeletedMetadata. So you need to check the class of the meta-data object to see what you can extract from it. (I wrote a category so that I can call -isDirectory, -isFile or -isDeleted on the meta-data object rather than have to write out -isKindOfClass: each time.)

     

    (I’ve been getting to grips with the new API msyelf over the past few days, and the above comes from hounding Greg at Dropbox with questions. :) )

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,879 PostsLatest Activity: 2 hours ago
326 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!