Fix NPE exception on uploadDocument