Objective-C Dropbox: Dropbox Move a File to another Folder

Back to Index

Move a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be moved.

Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-move

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/move_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"from_path\": \"/Homework/math/ghost_emoji.txt\",\"to_path\": \"/Halloween/emojis/ghost.txt\",\"allow_shared_folder\": false,\"autorename\": false,\"allow_ownership_transfer\": false}"

Objective-C Example

#import <CkoRest.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://api.dropboxapi.com/2/files/move_v2
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"api.dropboxapi.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

//  See the Online Tool for Generating JSON Creation Code
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"from_path" value: @"/Homework/math/ghost_emoji.txt"];
[json UpdateString: @"to_path" value: @"/Halloween/emojis/ghost.txt"];
[json UpdateBool: @"allow_shared_folder" value: NO];
[json UpdateBool: @"autorename" value: NO];
[json UpdateBool: @"allow_ownership_transfer" value: NO];

[rest AddHeader: @"Authorization" value: @"Bearer DROPBOX-ACCESS-TOKEN"];
[rest AddHeader: @"Content-Type" value: @"application/json"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/2/files/move_v2" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
if (respStatusCode >= 400) {
    NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jsonResponse = [[CkoJsonObject alloc] init];
[jsonResponse LoadSb: sbResponseBody];

//  See the Online Tool for Generating JSON Parse Code

NSString *from_path = [jsonResponse StringOf: @"from_path"];
NSString *to_path = [jsonResponse StringOf: @"to_path"];
BOOL allow_shared_folder = [jsonResponse BoolOf: @"allow_shared_folder"];
BOOL autorename = [jsonResponse BoolOf: @"autorename"];
BOOL allow_ownership_transfer = [jsonResponse BoolOf: @"allow_ownership_transfer"];

Sample JSON Response Body

{
  "from_path": "/Homework/math/ghost_emoji.txt",
  "to_path": "/Halloween/emojis/ghost.txt",
  "allow_shared_folder": false,
  "autorename": false,
  "allow_ownership_transfer": false
}