cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Dropbox API - Objective C - uploadData - versioned updates

Explorer | Level 3

Objective-C API Question 

 

Previously when I uploaded files (old API) dropbox would create numbered versions if the file was already there.

 

I am trying to do this same thing using the "uploadData" file route, like this:

 

 DBFILESWriteMode *mode = [[DBFILESWriteMode alloc] initWithUpdate:parentRev];

// parentRev is null here, what should it be ?

 

[[client.filesRoutes uploadData:[path stringByAppendingPathComponent:name] mode:mode autorename:false clientModified:nil mute:false inputData:data]

     setResponseBlock:^(DBFILESFileMetadata *metadata, DBFILESUploadError *routeError, DBRequestError *networkError) {

         

         if (metadata) {

             [self uploadedFile:[path stringByAppendingPathComponent:name] from:localFileURL.absoluteString metadata:metadata];

         } else {

             [self uploadFileFailedWithRouteError:routeError andNetworkError:networkError];

        } 

     }];

 

This always fails, with the error message:

 

2018-01-12 16:50:45.010 Shot Lister[93699:4378867] There was an error uploading the file

RouteError - (null)

NetworkError - DropboxBadInputError[{

    ErrorContent = "Error in call to API function \"files/upload\": HTTP header \"Dropbox-API-Arg\": mode: missing 'update' key";

    RequestId = 80a4b8c090dd70cb191ff3182e76c4e1;

    StatusCode = 400;

    UserMessage = nil;

}];

 

If I initWithOverWrite it works just fine.

 

 

"" 

 

3 Replies 3
Highlighted

Re: Dropbox API - Objective C - uploadData - versioned updates

Dropboxer
Dropboxer

When using the "update" write mode, the "parentRev" value should be the latest FileMetadata.rev value you saw for the file. That allows you to safely overwrite the file without accidentally overwriting a newer version. (It will create a conflict if the rev value you supply isn't actually the latest.)

 

Based on your description though, it sounds like you might actually want the "add" write mode. There's more information on the different write modes in that documentation.

Highlighted

Re: Dropbox API - Objective C - uploadData - versioned updates

Explorer | Level 3

the "add Write" mode sounds like exactly what I need.

However, it gives me this error when I try it ( do I still need the parentRev somehow ?)

 

There was an error uploading the file

RouteError - {

    ".tag" = path;

    path =     {

        reason =         {

            ".tag" = conflict;

            conflict =             {

                ".tag" = file;

            };

        };

        "upload_session_id" = AAAAAAAALlfY4TOhRrLTZw;

    };

}

NetworkError - DropboxHttpError[{

    ErrorContent = "path/conflict/file/.";

    RequestId = f3592a2cc49f18bb997e881887eba543;

    StatusCode = 409;

    UserMessage = nil;

}];

Highlighted

Re: Dropbox API - Objective C - uploadData - versioned updates

Dropboxer
Dropboxer

Apologies, I should have mentioned, in order to get the behavior you're looking for, you'll also need to set `autorename` in addition to using the 'add' write mode, e.g.:

 

https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESUserAuthRoutes.html#/c:ob...:

 

When using the 'add' write mode, uploading to a path that already contains a file will create a "conflict", and the `autorename` parameter controls what happens when there's a conflict. 

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?