Java Box SDK - Thumbnail Not Retrieved On First Request

New post



  • sgarlanka

    There should no reason this is failing on the first attempt. Your code looks right. If there is any other relevant information you can give that you think may be the source of the issue, I can look at it further.

    Comment actions Permalink
  • mbrooks11

    Hey, thanks for the reply. I really don't have any ideas what is causing this but I can share a little more about how we are using the API.


    We have a web application where users can upload files and we do some editing to the file. The edited file ends up as a .TIFF but the same behavior can be seen with a .PNG. The files are uploaded via the API like this (some error checking and a call to our database removed for brevity);


    public String uploadFile(String parentFolderId, String fileName, byte[] fileBytes, String username){
    	String resultingId = null;
    	BoxFolder myFolder = new BoxFolder(this.api, parentFolderId);
    	InputStream fileInput = new ByteArrayInputStream(fileBytes);
    	BoxFile.Info fileInfo = myFolder.uploadFile(fileInput, fileName); 
    	resultingId = fileInfo.getID();
    	return resultingId;


    parentFolderId is the box ID for the folder we are storing these files in. The files upload correctly and are visible in box's UI. I don't think how we upload the file is an issue but I'm trying to give you any helpful context I can.


    Here is a main method that also demonstrates the behavior for me. This approach uses a developer token instead of the config.json. If I debug this and sit on the "waiting..." statement for a few seconds (maybe 5 seconds), the subsequent thumbnail request always works. It doesn't matter how long I wait between the uploadFile() and the first getThumbnail() call - it always returns me an empty array. Box folder ID, developer token and test image path have been masked.


    	public static void main(String[] args) throws IOException{
    		String parentFolderId = "###########";
    		String filePath = "C:/path/to/an/image.png";
    		File file = new File(filePath);
    		FileInputStream fis = new FileInputStream(file);
    		String filename = "mytestfile.png";
    		BoxAPIConnection api = new BoxAPIConnection("################################");
    		BoxFolder myFolder = new BoxFolder(api, parentFolderId);
    		BoxFile.Info fileInfo = myFolder.uploadFile(fis, filename);
    		String resultingId = fileInfo.getID();
    		BoxFile boxfile = new BoxFile(api, resultingId);
    		byte[] thumbnailBytes = boxfile.getThumbnail(BoxFile.ThumbnailFileType.PNG, 32, 32, 32, 32);
    		thumbnailBytes = boxfile.getThumbnail(BoxFile.ThumbnailFileType.PNG, 32, 32, 32, 32);


    Other requests using the API on this file work on the first request (e.g. getting the full size image or the file name in box) but only the thumbnail is giving us trouble.

    Comment actions Permalink
  • sgarlanka


    Sorry for the delayed response. Take a look at the thumbnail docs at In the case of a 202 status code a thumbnail is not yet generated and you would have to retry the request after a certain amount of time. I would check if a 202 status code is returned from the call. If this is the case, then what is happening is expected behavior. One way to check is to manually make a Postman request. This is a collection of Box API Endpoints for postman: The other option is to go into the getThumbnail() method in your project ( and print out the response to check the status code.

    Comment actions Permalink
  • mbrooks11

    Yes, this was the case. Thanks for the help! 

    Comment actions Permalink

Please sign in to leave a comment.