cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right 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: 

Re: Getting rev from DBFILESMetadata in obj-c API 2

Getting rev from DBFILESMetadata in obj-c API 2

billymeltdown
Explorer | Level 4
Go to solution

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! 

1 Accepted Solution

Accepted Solutions

Keith B.7
Helpful | Level 7
Go to solution

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. :slightly_smiling_face: )

View solution in original post

2 Replies 2

Keith B.7
Helpful | Level 7
Go to solution

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. :slightly_smiling_face: )

billymeltdown
Explorer | Level 4
Go to solution

Ah, ha! Awesome, thanks Keith!

Need more support?