You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

Naga Abhinaya T's avatar
Naga Abhinaya T
Explorer | Level 4
8 years ago

Sending Folder IDs instead of Folder path in APIs

Hi,

 

We are developing an app wherein we are storing the folderpath to upload files directly to theat folder in Dropbox. If the user unknowingly changes the folder name, we face conflict while invoking upload api or the file is uploaded to the newly created folder of that name. To overcome this issue, it would be better if we could pass the folder id instead of folder path, to upload api. Is it possible? Also is there a way to throw an exception when the folder path is not found while uploading, instead of creating the folder?

 

  • Yes, you can upload a file into a folder, using a path relative to the ID for the folder, like "<FOLDER ID>/<FILE NAME>".

     

    Here's a simple example of what that would look like:

     

    curl -X POST https://api.dropboxapi.com/2/files/create_folder_v2 \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"/test_256136_folder\"}"
    
    # {
    #   "metadata": {
    #     "name": "test_256136_folder",
    #     "path_lower": "/test_256136_folder",
    #     "path_display": "/test_256136_folder",
    #     "id": "id:25N5ksooX-sAAAAAAAMgxg"
    #   }
    # }
    
    curl -X POST https://content.dropboxapi.com/2/files/upload \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Dropbox-API-Arg: {\"path\": \"id:25N5ksooX-sAAAAAAAMgxg/test_256136_file.txt\"}" \
        --header "Content-Type: application/octet-stream" \
        --data-binary "test data"
    
    # {
    #   "name": "test_256136_file.txt",
    #   "path_lower": "/test_256136_folder/test_256136_file.txt",
    #   "path_display": "/test_256136_folder/test_256136_file.txt",
    #   "id": "id:25N5ksooX-sAAAAAAAMgxw",
    #   "client_modified": "2017-12-11T15:45:12Z",
    #   "server_modified": "2017-12-11T15:45:13Z",
    #   "rev": "72689021eccc7",
    #   "size": 9,
    #   "content_hash": "824979ede959fefe53082bc14502f8bf041d53997ffb65cbbe3ade5803f7fb76"
    # }
    
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Yes, you can upload a file into a folder, using a path relative to the ID for the folder, like "<FOLDER ID>/<FILE NAME>".

     

    Here's a simple example of what that would look like:

     

    curl -X POST https://api.dropboxapi.com/2/files/create_folder_v2 \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"/test_256136_folder\"}"
    
    # {
    #   "metadata": {
    #     "name": "test_256136_folder",
    #     "path_lower": "/test_256136_folder",
    #     "path_display": "/test_256136_folder",
    #     "id": "id:25N5ksooX-sAAAAAAAMgxg"
    #   }
    # }
    
    curl -X POST https://content.dropboxapi.com/2/files/upload \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Dropbox-API-Arg: {\"path\": \"id:25N5ksooX-sAAAAAAAMgxg/test_256136_file.txt\"}" \
        --header "Content-Type: application/octet-stream" \
        --data-binary "test data"
    
    # {
    #   "name": "test_256136_file.txt",
    #   "path_lower": "/test_256136_folder/test_256136_file.txt",
    #   "path_display": "/test_256136_folder/test_256136_file.txt",
    #   "id": "id:25N5ksooX-sAAAAAAAMgxw",
    #   "client_modified": "2017-12-11T15:45:12Z",
    #   "server_modified": "2017-12-11T15:45:13Z",
    #   "rev": "72689021eccc7",
    #   "size": 9,
    #   "content_hash": "824979ede959fefe53082bc14502f8bf041d53997ffb65cbbe3ade5803f7fb76"
    # }
    
    • Greg-DB's avatar
      Greg-DB
      Icon for Dropbox Staff rankDropbox Staff
      There isn't a way to disable the automatic creation of parent folders when uploading to a path though, but I'll pass this along as a feature request.