Get file ID of a given path

前端 未结 3 2171
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 22:02

is there a direct method to get file ID by giving a path (e.g. /some/folder/deep/inside/file.txt)? I know this can be done by recursively checking folder\'s contents, but a simp

3条回答
  •  长情又很酷
    2021-02-19 22:36

    An alternative to this would be to extract the target file/folder name from the path and search for it using the search API

    like this: https://api.box.com/2.0/search?query=filename.txt

    This gives back all the matching entries with their path_collections which provides the whole hierarchy for every entry. Something like this:

     "path_collection": {
                    "total_count": 2,
                    "entries": [
                        {
                            "type": "folder",
                            "id": "0",
                            "sequence_id": null,
                            "etag": null,
                            "name": "All Files"
                        },
                        {
                            "type": "folder",
                            "id": "2988397987",
                            "sequence_id": "0",
                            "etag": "0",
                            "name": "dummy"
                        }
                    ]
               }
    

    Path for this entry can be reverse engineered as /dummy/filename.txt

    Just compare this path against the path you're looking for. If it matches, then that's the search result you're looking for. This is just to reduce the number of ReST calls you need to make to arrive at the result. Hope it makes sense.

提交回复
热议问题