Visual Basic 6.0 Dropbox: Dropbox Copy a File or Folder

Back to Index

Copy 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 copied.

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

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/copy_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"from_path\": \"/ocean/starfish.jpg\",\"to_path\": \"/ocean/starfish2.jpg\",\"allow_shared_folder\": false,\"autorename\": false,\"allow_ownership_transfer\": false}"

Visual Basic 6.0 Example

Dim rest As New ChilkatRest
Dim success As Long

'  URL: https://api.dropboxapi.com/2/files/copy_v2
Dim bTls As Long
bTls = 1
Dim port As Long
port = 443
Dim bAutoReconnect As Long
bAutoReconnect = 1
success = rest.Connect("api.dropboxapi.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
    Debug.Print rest.LastErrorText
    Exit Sub
End If

'  See the Online Tool for Generating JSON Creation Code
Dim json As New ChilkatJsonObject
success = json.UpdateString("from_path","/ocean/starfish.jpg")
success = json.UpdateString("to_path","/ocean/starfish2.jpg")
success = json.UpdateBool("allow_shared_folder",0)
success = json.UpdateBool("autorename",0)
success = json.UpdateBool("allow_ownership_transfer",0)

success = rest.AddHeader("Authorization","Bearer DROPBOX-ACCESS-TOKEN")
success = rest.AddHeader("Content-Type","application/json")

Dim sbRequestBody As New ChilkatStringBuilder
success = json.EmitSb(sbRequestBody)
Dim sbResponseBody As New ChilkatStringBuilder
success = rest.FullRequestSb("POST","/2/files/copy_v2",sbRequestBody,sbResponseBody)
If (success <> 1) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

Dim respStatusCode As Long
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Status Code = " & respStatusCode
    Debug.Print "Response Header:"
    Debug.Print rest.ResponseHeader
    Debug.Print "Response Body:"
    Debug.Print sbResponseBody.GetAsString()
    Exit Sub
End If

Dim jsonResponse As New ChilkatJsonObject
success = jsonResponse.LoadSb(sbResponseBody)

'  See the Online Tool for Generating JSON Parse Code

Dim metadataTag As String
metadataTag = jsonResponse.StringOf("metadata."".tag""")
Dim metadataName As String
metadataName = jsonResponse.StringOf("metadata.name")
Dim metadataPath_lower As String
metadataPath_lower = jsonResponse.StringOf("metadata.path_lower")
Dim metadataPath_display As String
metadataPath_display = jsonResponse.StringOf("metadata.path_display")
Dim metadataId As String
metadataId = jsonResponse.StringOf("metadata.id")
Dim metadataClient_modified As String
metadataClient_modified = jsonResponse.StringOf("metadata.client_modified")
Dim metadataServer_modified As String
metadataServer_modified = jsonResponse.StringOf("metadata.server_modified")
Dim metadataRev As String
metadataRev = jsonResponse.StringOf("metadata.rev")
Dim metadataSize As Long
metadataSize = jsonResponse.IntOf("metadata.size")
Dim metadataContent_hash As String
metadataContent_hash = jsonResponse.StringOf("metadata.content_hash")

Sample JSON Response Body

{
  "metadata": {
    ".tag": "file",
    "name": "starfish2.jpg",
    "path_lower": "/ocean/starfish2.jpg",
    "path_display": "/ocean/starfish2.jpg",
    "id": "id:JSXYsxHo1hAAAAAAAAAADg",
    "client_modified": "2018-10-22T22:38:18Z",
    "server_modified": "2018-10-22T22:40:38Z",
    "rev": "1c482db15f",
    "size": 6229,
    "content_hash": "9fa9d692d0762ee759c22dea993c7de0068f9ba2ca842e761a1636d3b0b3cbba"
  }
}