cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iOS API v2: possible to overwrite files at upload?

iOS API v2: possible to overwrite files at upload?

tannchri
Explorer | Level 4
Go to solution

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?

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

You can certainly overwrite files using the API. For example, use -uploadData:mode:autorename:clientModified:mute:inputData: and pass in the desired 'mode' parameter, which should be a DBFILESWriteMode. You can use the 'overwrite' mode, but using 'update' with a rev value is safer, as it prevents accidentally overwriting new data the app wasn't aware of.

View solution in original post

5 Replies 5

Mark
Super User II
Go to solution
*moves to API forum*

 


:penguin::penguin: - :penguin: - :penguin: - :penguin:


Heart Did this post help you? If so please mark it for some Kudos below. 


:white_check_mark: Did this post fix your issue/answer your question? If so please press the 'Accept as Solution' button to help others find it.


:arrows_counterclockwise: Did this post not resolve your issue? If so please give us some more information so we can try and help - please remember we cannot see over your shoulder so be as descriptive as possible! 


 

tannchri
Explorer | Level 4
Go to solution
Thanks! Don't know how I got lost here.

Greg-DB
Dropbox Staff
Go to solution

You can certainly overwrite files using the API. For example, use -uploadData:mode:autorename:clientModified:mute:inputData: and pass in the desired 'mode' parameter, which should be a DBFILESWriteMode. You can use the 'overwrite' mode, but using 'update' with a rev value is safer, as it prevents accidentally overwriting new data the app wasn't aware of.

tannchri
Explorer | Level 4
Go to solution

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
Dropbox Staff
Go to solution

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);
        }

}];

 

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    tannchri Explorer | Level 4
  • User avatar
    Mark Super User II
What do Dropbox user levels mean?