Skip to main content

I want to navigate a series of folders and pull file name & file size information, using the Java api.

I am using the recommended approach, which is basically to enumerate all the BoxItems found in each BoxFolder.

However it is extremely slow.

Is there not a single command that can be sent to return ALL of the BoxFolder's metadata contents in one go? i.e. the equivalent of the "ls" command?


By the way, when I say slow, I mean it takes almost 1 second to get each ItemInfo:

for (BoxItem.Info itemInfo : targetFolder) {
if (itemInfo instanceof BoxFolder.Info) {
...
etc.

 



Ok, I finally figured out why it is so slow:  By default, the method gets only one Box.FileInfo object at a time from the server.  To speed up you need to use pagination with max limit of 100.  Something like the following:

 


int offset = 0; //Start
int pageSize = 100;
while (true) {
   Collection itemsInFolder = targetFolder.getChildrenRange(offset, pageSize, "name", "size");
   for (BoxItem.Info itemInfo : itemsInFolder) {
       if (itemInfo instanceof BoxFile.Info) {
             ....
        }
        else if (itemInfo instanceof BoxFolder.Info) {

            ...
        }
    }
    if (itemsInFolder.size() < pageSize) break;           //Less than max returned signals end
    offset += pageSize;
}

 

 



Reply