cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sending Folder IDs instead of Folder path in APIs

Sending Folder IDs instead of Folder path in APIs

Naga Abhinaya T
Explorer | Level 4
Go to solution

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?

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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"
# }

View solution in original post

10 Replies 10

Greg-DB
Dropbox Staff
Go to solution

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
Dropbox Staff
Go to solution
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.

Naga Abhinaya T
Explorer | Level 4
Go to solution

Thanks Greg!

Naga Abhinaya T
Explorer | Level 4
Go to solution

Hi Greg,

 

Using the solution given, I was able to list files in a folder using the folderId of the folder. Can I use the folder Id for /create_folder_v2 api as well. I tried the same and got the following error

 

 

"Error in call to API function "files/create_folder_v2": request body: path: 'id:dB3gk09sK_QAAAAAAAAAgw' did not match pattern '(/(.|[\r\n])*)|(ns:[0-9]+(/.*)?)'"

 

Request Body:

 

{
"path":"id:dBxxxxxxxxxxxxx",
"autorename": false
}

 

Can you please advise on this?

Greg-DB
Dropbox Staff
Go to solution
The create_folder_v2 endpoint doesn't support file IDs like this.

Also, a file ID identifies an existing item, and is assigned when that item is created. The create_folder_v2 endpoint creates a new folder, so supplying just a file ID wouldn't make sense, as it identifies an existing item. Do you mean you want to be able to create a new folder relative to an existing parent folder, as with my upload example above, where you identify that existing parent via ID? That's not possible with create_folder_v2, but I'll be happy to send that along as a feature request.

Naga Abhinaya T
Explorer | Level 4
Go to solution

Hi Greg,

 

Can you let me know as when this feature will be included? Any tentative timeframe?

Greg-DB
Dropbox Staff
Go to solution
No, unfortunately I don't have a timeline for if or when this might be added.

Naga Abhinaya T
Explorer | Level 4
Go to solution

Thanks Greg!

zainulabideen
Explorer | Level 4
Go to solution

Hi Greg,

I have a similar requirement. I want to create a folder by passing a parent folder id to the path. Do your API supports this now? As the question was asked more than a year ago, Is something changed?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    zainulabideen Explorer | Level 4
  • User avatar
    Naga Abhinaya T Explorer | Level 4
What do Dropbox user levels mean?