how to restore file in dropbox programmatically

Go To StackoverFlow.com

1

i'm a newbie in dropbox development in IOS, i'm still learning about implementing dropbox in my app, the app is a text editor, i want to make it support for upload and downloading file in dropbox. In my app, i just can make some change in text and then upload it into dropbox, but i cant restore it into the last version. I have read Dropbox Rest API and read about https://api.dropbox.com/1/restore/<root>/<path>

but i dont know what to do, can somebody help me?

Thank you

2012-04-04 06:35
by R. Dewi


1

Try this

/* Restores a file at path as it existed at the given rev and returns the metadata of the restored file after restoration */

- (void)restoreFile:(NSString *)path toRev:(NSString *)rev;

where path is the path of the DropBox file that has to restored and rev is the Revision to which it has to be restored

and its delegate methods are

- (void)restClient:(DBRestClient*)client restoredFile:(DBMetadata *)fileMetadata;
- (void)restClient:(DBRestClient*)client restoreFileFailedWithError:(NSError *)error;

and you can use these to get the revisions list of the particular file

/* Loads a list of up to 10 DBMetadata objects representing past revisions of the file at path */

- (void)loadRevisionsForFile:(NSString *)path;

/* Same as above but with a configurable limit to number of DBMetadata objects returned, up to 1000 */

- (void)loadRevisionsForFile:(NSString *)path limit:(NSInteger)limit;

and their Delegate Methods are

- (void)restClient:(DBRestClient*)client loadedRevisions:(NSArray *)revisions forFile:(NSString *)path;
- (void)restClient:(DBRestClient*)client loadRevisionsFailedWithError:(NSError *)error;

example

    NSString *filePath = @"/Contacts";
    NSString *revisionStr = @"a1067dc176";   // sample revisionString

    [[self restClient] loadRevisionsForFile:filePath limit:10];

    [[self restClient] restoreFile:filePath toRev:revisionStr];

// Delegate Methods

- (void)restClient:(DBRestClient*)client loadedRevisions:(NSArray *)revisions forFile:(NSString *)path{

    for (DBMetadata *file in revisions) 
    {
        NSLog(@"MetaData's Revisions \t%@", file.rev);
    }
}
- (void)restClient:(DBRestClient*)client loadRevisionsFailedWithError:(NSError *)error{

}

- (void)restClient:(DBRestClient*)client restoredFile:(DBMetadata *)fileMetadata{
    NSLog(@"Restored FileMetaData Path : %@",fileMetadata.path);
        NSLog(@"Restored FileMetaData rev : %@",fileMetadata.rev);
}
- (void)restClient:(DBRestClient*)client restoreFileFailedWithError:(NSError *)error{
     NSLog(@"There was an error restoring the file - %@", error);
}
2012-04-04 08:26
by Bala
Ads