We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. 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);
                }
        
        }];

         

         

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 2 hours ago
325 Following

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

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!