cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: metadata.rev in API v2?

metadata.rev in API v2?

MateusP
Helpful | Level 6
Go to solution

Better late than never, I'm trying to migrate my Android app to API v2.  Currently, when downloading a file from a user's linked Dropbox account, I first obtain the file revision...

 

@Override
protected Boolean doInBackground(Void... params) {
    try {
        // Get Dropbox file revision
        Entry metadata = mDbxApi.metadata(mPath+mFilename, 5, null, true, null);
        String dbxFileRev = metadata.rev;

 

I'm struggling to workout how to do this in V2 because it seems I have to somehow use FileMetadata instead.

FileMetadata metadata = ?? mPath+mFilename ??
String dbxFileRev = metadata.getRev();

 

As you can guess, I'm a hobby developer and not a pro!

 

Many thanks,

M.

1 Accepted Solution

Accepted Solutions

MateusP
Helpful | Level 6
Go to solution

OK so I worked it out and it's really simple -  you just cast to FileMetadata...

FileMetadata metadata = (FileMetadata) mDbxClient.files().getMetadata(mPath+mFilename);
String dbxFileRev = metadata.getRev();

If the file is not found, it'll throw a 'FileNotFoundException'

View solution in original post

4 Replies 4

MateusP
Helpful | Level 6
Go to solution

OK so I worked it out and it's really simple -  you just cast to FileMetadata...

FileMetadata metadata = (FileMetadata) mDbxClient.files().getMetadata(mPath+mFilename);
String dbxFileRev = metadata.getRev();

If the file is not found, it'll throw a 'FileNotFoundException'

Greg-DB
Dropbox Staff
Go to solution

I'm glad to see you found this already. Yes, some properties are only available on FileMetadata, which is a subclass of Metadata, so you need to cast objects as necessary.

 

There's an example of how you can check for this here:

 

https://github.com/dropbox/dropbox-sdk-java/blob/7ecc15cf0f51d6ae2ba5cdb334aac2c2f3474b87/examples/a...

VarunRaj
New member | Level 2
Go to solution

What is mPath??

Is it /App_folder_name/filename ??

Greg-DB
Dropbox Staff
Go to solution

@VarunRaj The getMetadata method takes the path to the file you're looking for as the "path" parameter. In the sample above, the value being passed in is "mPath+mFilename", which would mean that "mPath" is the path to the parent folder that contains the file with name "mFilename", if any.

 

Note that if you're using an app with the app folder permission, you should not explicitly pass in the app folder name. You just operate relative to the app folder, so for example, to reference a file "test.txt" direclty in the app folder, you would just pass in "/test.txt".

 

You can also get the path from the pathLower property on Metadata entries, e.g., as returned by listFolder.

Need more support?