We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

tannchri's avatar
tannchri
Explorer | Level 4
8 years ago

iOS API v2: possible to overwrite files at upload?

I'm using the objective-c SDK for Dropbox API v2 and trying to do something which should be remarkably simple: upload text files to the user's Dropbox folder and if any changes are made to the file on the device, upload those changes.

However, I'm running into a strategic issue wherein the code refuses to overwrite an existing file. So if a user opens a file on their device, makes a change, I want that change to be pushed to their Dropbox. What's the best way to make this happen? I don't see anything about overwriting files for uploads or updating existing documents.

 

Using the basic upload code currently:

 

[[[dbclient.filesRoutes uploadData:[NSString stringWithFormat:@"/%@", fileName] inputData:fileData]
              response:^(DBFILESFileMetadata *result, DBFILESUploadError *routeError, DBRequestError *error)

Is there an easy way to force overwrites? It would be nice to not have to loop through the Dropbox folder and check if the file currently exists before updating it.

What I'd like to do is simply upload the file, and if it already exists just overwrite it. Is this not possible? Am I going about this incorrectly?

 

    • tannchri's avatar
      tannchri
      Explorer | Level 4

      Thank you!

       

      Though I'm still having trouble with this, and am unable to find any resolution elsewhere. Is this not the correct way to write this? "

      dbclient.filesRoutes uploadData:fileName mode:DBFILESWriteModeOverwrite ..."

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        That woud look like this:

         

        NSString *path = ...
        NSData *data = ...
        DBFILESWriteMode *mode = [[DBFILESWriteMode alloc] initWithOverwrite];
        
        [[client.filesRoutes uploadData:path mode:mode autorename:false clientModified:nil mute:false inputData:data] response:^(DBFILESFileMetadata *metadata, DBFILESUploadError *routeError, DBRequestError *error) {
        
                if (metadata) {
                    NSLog(@"%@\n", metadata);
                } else {
                    NSLog(@"%@\n%@\n", routeError, error);
                }
        
        }];