Rishabh Jain
Rishabh Jain

Reputation: 536

Getting ID of File after uploading in Box

I am using java-box-sdk to upload files to box. Currently I am able to upload files, but to do any operation on that file I need ID of that file. How can I get ID of the uploaded file . Here is my code

BoxAPIConnection api = new BoxAPIConnection(code);
            BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
            System.out.format("Welcome, %s <%s>!\n\n", userInfo.getName(), userInfo.getLogin());
            BoxFolder rootFolder = BoxFolder.getRootFolder(api);
            FileInputStream stream = new FileInputStream("/home/stuart/two.txt");
            rootFolder.uploadFile(stream, "two.txt");
            stream.close();

Upvotes: 0

Views: 423

Answers (1)

J_D
J_D

Reputation: 736

Loop through the BoxFolder and get the ID from BoxItem.Info. Here is the example from http://opensource.box.com/box-java-sdk/

BoxFolder rootFolder = BoxFolder.getRootFolder(api);

for (BoxItem.Info itemInfo : rootFolder) {

System.out.format("[%s] %s\n", itemInfo.getID(), itemInfo.getName());

}

Upvotes: 4

Related Questions