9

I am developing an iOS application using Dropbox API. While uploading a file using the dropbox API, I just want to overwrite the existing file with the same name. How can I set the parent rev and what value? Thanks!

Maksim
  • 2,054
  • 3
  • 17
  • 33
vandana
  • 111
  • 2
  • 4

4 Answers4

6

Get all the files in the directory with [[self restclient] loadMetadata:@"/"]

in the delegate - (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata you get all the details of each file. Scan through all the files with file name of your interest and get the rev details with file.rev and store it.

When you want to replace the file, for parentrev argument, give the nsstring as what you stored with file.rev

Boaz
  • 4,549
  • 2
  • 27
  • 40
sumanth
  • 61
  • 1
  • 1
2

https://www.dropbox.com/developers/reference/api#files_put

Refering to the Dropbox API you just have to specify the parent_rev parameter. If you don't know the parent_rev, just call the https://www.dropbox.com/developers/reference/api#metadata for the file. In the response of that call, you will find the parent_rev

Lars
  • 512
  • 1
  • 3
  • 13
1

In the uploadFile method set the withParentRev to nil.

user523234
  • 14,323
  • 10
  • 62
  • 102
  • I need to overwrite the existing file. While giving parentRev nill create new files each time. – vandana May 21 '12 at 10:17
  • Oops... Lars pointed to the right direction: you need to read the metadata of the existing file first to get the parentRev info. Also you can used the deprecated method uploadFile:toPath:fromPath: – user523234 May 21 '12 at 10:47
  • could you please share your solution? – OscarTheGrouch Feb 09 '13 at 04:27
1

One more interesting way is

[[self restclient] loadrevisionsforfile:@"/test.pdf"]

This assume you know your test.pdf is under root directory

in the delegate

-(void) restclient:(DBRestClient *)client loadedRevisions:(NSArray *)revisions forfile:(NSString *)path

revisions array holds the history of all revisions of test.pdf file meaning the array count indicates the number of times test.pdf has been updated

DBMetaData *y = [revisions objectatindex:0]

At index 0, the revision number is the latest updated test.pdf.

For updating the existing test.pdf,y.rev can be used for argument in parentrev

IronManGill
  • 7,222
  • 2
  • 31
  • 52
sumanth
  • 11
  • 1
  • What if there are 1000 revisions? This seems a waste, but if you call with a limit of 1, then it may be faster than getting all the metadata. – Tom Andersen Sep 11 '13 at 13:11