Getting the file complete path using box api

Highlighted
Occasional Contributor

Getting the file complete path using box api

HI,

Java Box api to get the complete folder path of the uploaded file. Code snippet to get the folder path could you please help me on this.

Thanks & regards,

Kalyan

2 REPLIES 2
Highlighted
Box Employee

Re: Getting the file complete path using box api

@kalyanch The list of folders in the file path is contained in the `path_collection` field of the API response; you need to concatenate the names of all those folders.  Something like this should do the trick:

 

BoxFile.Info file = new BoxFile(api, fileID).getInfo();

String path = "";
for (BoxFolder.Info folder : file.getPathCollection()) {
    path += "/" + folder.getName();
}

path += file.getName();

// path contains a string like "/All Files/My Stuff/Document.pdf"
Highlighted
First-time Contributor

Re: Getting the file complete path using box api

File object has an attribute called "path_collection."

You can look at this for more detail:

https://developer.box.com/reference/resources/file/#param-path_collection