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

sbrownnw's avatar
sbrownnw
Explorer | Level 4
2 years ago

restored folders and files have different ids than their originally added entities

given dropbox UI has no folders or files in it

when I create a subfolder

and add file1 to the subfolder

and add file2 to the subfolder

and note the ids for the new subfolder and two new files

and when I delete the subfolder

and when I restore file1

then the restored subfolder id is different than the originally added one in step 2

and the restored file1 id is different than the originally added one in step 3

 

why is this?  it seems like an entity's id (primary key for folder or file) should always stay the same whether it is deleted, restored or whatever.

  • In the "restore file1" step, you're only restoring the file itself, not the original folder. When adding or restoring a file, if a parent path component (the folder, in this case) doesn't already exist, it will be automatically created. That automatically created folder is a new folder, not a restored folder (and it may or may not be at the same path as the original parent folder, e.g., since you can restore a file to a different location).

     

    As for the file ID of the restored file itself, I would expect that to be the same, and it is in my testing. Here's an example I just ran through:

    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_691719_folder"}'
    
    # {
    #   "metadata": {
    #     "name": "test_691719_folder",
    #     "path_lower": "/test_691719_folder",
    #     "path_display": "/test_691719_folder",
    #     "id": "id:25N5ksooX-sAAAAAAAQyqA"
    #   }
    # }  
    
    curl -X POST https://content.dropboxapi.com/2/files/upload \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/octet-stream' \
      --header 'Dropbox-API-Arg: {"path":"/test_691719_folder/test_691719_file"}' \
      --data-binary @'test.txt'
    
    # {
    #   "name": "test_691719_file",
    #   "path_lower": "/test_691719_folder/test_691719_file",
    #   "path_display": "/test_691719_folder/test_691719_file",
    #   "id": "id:25N5ksooX-sAAAAAAAQyqQ",
    #   "client_modified": "2023-06-14T18:42:28Z",
    #   "server_modified": "2023-06-14T18:42:29Z",
    #   "rev": "5fe1b50581a7c021eccc7",
    #   "size": 27,
    #   "is_downloadable": true,
    #   "content_hash": "cceac37da5288a6b6716737310c14305c9b16a6e0ff0abce4a306c3de3a59f75"
    # }
    
    curl -X POST https://api.dropboxapi.com/2/files/delete_v2 \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder"}'
    
    # {
    #   "metadata": {
    #     ".tag": "folder",
    #     "name": "test_691719_folder",
    #     "path_lower": "/test_691719_folder",
    #     "path_display": "/test_691719_folder",
    #     "id": "id:25N5ksooX-sAAAAAAAQyqA"
    #   }
    # }
    
    curl -X POST https://api.dropboxapi.com/2/files/restore \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder/test_691719_file","rev":"5fe1b50581a7c021eccc7"}'
    
    # {
    #   "name": "test_691719_file",
    #   "path_lower": "/test_691719_folder/test_691719_file",
    #   "path_display": "/test_691719_folder/test_691719_file",
    #   "id": "id:25N5ksooX-sAAAAAAAQyqQ",
    #   "client_modified": "2023-06-14T18:42:28Z",
    #   "server_modified": "2023-06-14T18:43:47Z",
    #   "rev": "5fe1b5501cafb021eccc7",
    #   "size": 27,
    #   "is_downloadable": true,
    #   "content_hash": "cceac37da5288a6b6716737310c14305c9b16a6e0ff0abce4a306c3de3a59f75"
    # }  
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder"}'
    
    # {
    #   ".tag": "folder",
    #   "name": "test_691719_folder",
    #   "path_lower": "/test_691719_folder",
    #   "path_display": "/test_691719_folder",
    #   "id": "id:25N5ksooX-sAAAAAAAQyrA"
    # }
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder/test_691719_file"}'  
    
    # {
    #   ".tag": "file",
    #   "name": "test_691719_file",
    #   "path_lower": "/test_691719_folder/test_691719_file",
    #   "path_display": "/test_691719_folder/test_691719_file",
    #   "id": "id:25N5ksooX-sAAAAAAAQyqQ",
    #   "client_modified": "2023-06-14T18:42:28Z",
    #   "server_modified": "2023-06-14T18:43:47Z",
    #   "rev": "5fe1b5501cafb021eccc7",
    #   "size": 27,
    #   "is_downloadable": true,
    #   "content_hash": "cceac37da5288a6b6716737310c14305c9b16a6e0ff0abce4a306c3de3a59f75"
    # }

    If something's not working properly for you though, please share the steps/code to reproduce the issue and show us the unexpected output or error so we can look into it.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    In the "restore file1" step, you're only restoring the file itself, not the original folder. When adding or restoring a file, if a parent path component (the folder, in this case) doesn't already exist, it will be automatically created. That automatically created folder is a new folder, not a restored folder (and it may or may not be at the same path as the original parent folder, e.g., since you can restore a file to a different location).

     

    As for the file ID of the restored file itself, I would expect that to be the same, and it is in my testing. Here's an example I just ran through:

    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_691719_folder"}'
    
    # {
    #   "metadata": {
    #     "name": "test_691719_folder",
    #     "path_lower": "/test_691719_folder",
    #     "path_display": "/test_691719_folder",
    #     "id": "id:25N5ksooX-sAAAAAAAQyqA"
    #   }
    # }  
    
    curl -X POST https://content.dropboxapi.com/2/files/upload \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/octet-stream' \
      --header 'Dropbox-API-Arg: {"path":"/test_691719_folder/test_691719_file"}' \
      --data-binary @'test.txt'
    
    # {
    #   "name": "test_691719_file",
    #   "path_lower": "/test_691719_folder/test_691719_file",
    #   "path_display": "/test_691719_folder/test_691719_file",
    #   "id": "id:25N5ksooX-sAAAAAAAQyqQ",
    #   "client_modified": "2023-06-14T18:42:28Z",
    #   "server_modified": "2023-06-14T18:42:29Z",
    #   "rev": "5fe1b50581a7c021eccc7",
    #   "size": 27,
    #   "is_downloadable": true,
    #   "content_hash": "cceac37da5288a6b6716737310c14305c9b16a6e0ff0abce4a306c3de3a59f75"
    # }
    
    curl -X POST https://api.dropboxapi.com/2/files/delete_v2 \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder"}'
    
    # {
    #   "metadata": {
    #     ".tag": "folder",
    #     "name": "test_691719_folder",
    #     "path_lower": "/test_691719_folder",
    #     "path_display": "/test_691719_folder",
    #     "id": "id:25N5ksooX-sAAAAAAAQyqA"
    #   }
    # }
    
    curl -X POST https://api.dropboxapi.com/2/files/restore \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder/test_691719_file","rev":"5fe1b50581a7c021eccc7"}'
    
    # {
    #   "name": "test_691719_file",
    #   "path_lower": "/test_691719_folder/test_691719_file",
    #   "path_display": "/test_691719_folder/test_691719_file",
    #   "id": "id:25N5ksooX-sAAAAAAAQyqQ",
    #   "client_modified": "2023-06-14T18:42:28Z",
    #   "server_modified": "2023-06-14T18:43:47Z",
    #   "rev": "5fe1b5501cafb021eccc7",
    #   "size": 27,
    #   "is_downloadable": true,
    #   "content_hash": "cceac37da5288a6b6716737310c14305c9b16a6e0ff0abce4a306c3de3a59f75"
    # }  
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder"}'
    
    # {
    #   ".tag": "folder",
    #   "name": "test_691719_folder",
    #   "path_lower": "/test_691719_folder",
    #   "path_display": "/test_691719_folder",
    #   "id": "id:25N5ksooX-sAAAAAAAQyrA"
    # }
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Content-Type: application/json' \
      --data '{"path":"/test_691719_folder/test_691719_file"}'  
    
    # {
    #   ".tag": "file",
    #   "name": "test_691719_file",
    #   "path_lower": "/test_691719_folder/test_691719_file",
    #   "path_display": "/test_691719_folder/test_691719_file",
    #   "id": "id:25N5ksooX-sAAAAAAAQyqQ",
    #   "client_modified": "2023-06-14T18:42:28Z",
    #   "server_modified": "2023-06-14T18:43:47Z",
    #   "rev": "5fe1b5501cafb021eccc7",
    #   "size": 27,
    #   "is_downloadable": true,
    #   "content_hash": "cceac37da5288a6b6716737310c14305c9b16a6e0ff0abce4a306c3de3a59f75"
    # }

    If something's not working properly for you though, please share the steps/code to reproduce the issue and show us the unexpected output or error so we can look into it.

    • sbrownnw's avatar
      sbrownnw
      Explorer | Level 4

      I see, the folder being created after the file being restored was causing the failure I was seeing.  Yes, you are correct, the folder is a different entity (not sure why, with a different Id) but the restored file has the same Id as the originally added one.