Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

Java SDK - get created at for a file seems not to work

Answered
New post

Comments

3 comments

  • TheFelix

    Hey,

     

    I found out what is the error.

     

    First I was using a date time library function what returns the current time when the object is null. So the time I printed on the console actually was null.

    So I searched the community with this new insight and I found this post, which is exactly my problem:

    BoxItem.Info returns null for various properties

    So you can't get the created at from the item BoxFile.Info directly. Here is how it works:

    1. make a new BoxFile object using the ID of the BoxFile.Info
    2. from this new BoxFile object get again the BoxFile.Info
    3. on this BoxFile.Info object you can now get the created at time stamp

    So it is not a bug, it is rather on misleading design.

     

    Here is the changed code

    for (BoxItem.Info itemInfo : folder) {
        if (itemInfo instanceof BoxFile.Info) {
            BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
            System.out.println("  File: " + fileInfo.getName());
    
            // new part - first get the BoxFile and then again the BoxFile.Info of that
            BoxFile boxFile = new BoxFile(api, fileInfo.getID());
            BoxFile.Info newBoxFileInfo = boxFile.getInfo();
            DateTime curCreatedAt = new DateTime(newBoxFileInfo.getCreatedAt());
    
            DateTimeFormatter dateTimeFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
            System.out.println("    created_at: " + dateTimeFormat.print(curCreatedAt));
        }
    }

     

     

    0
    Comment actions Permalink
  • Murtza

     Thanks for updating the thread with the solution!

    0
    Comment actions Permalink
  • Box Sandbox User3

    String[] childrenFields = {"name", "createdAt", "size"};

    Iterable<BoxItem.Info> infos = folder.getChildren(childrenFields);

     

    "size" gets populated but not "createdAt". Better to get a new BoxFile.Info object from the id

    to fetch the "createdAt"

     

    0
    Comment actions Permalink

Please sign in to leave a comment.