Forum Discussion

MateusP's avatar
MateusP
Helpful | Level 6
9 years ago
Solved

metadata.rev in API v2?

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.

  • 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'

4 Replies

  • MateusP's avatar
    MateusP
    Helpful | Level 6
    9 years ago

    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'

  • VarunRaj's avatar
    VarunRaj
    New member | Level 2
    8 years ago

    What is mPath??

    Is it /App_folder_name/filename ??

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!