Page 1 of 1

Get a documents size

PostPosted:Wed Oct 29, 2014 12:52 pm
by holgrich
Hi all,

in Java, I would like to get a document's physical size (like "2032 KB"). Is this possible using the current version of the API? I tried
Code: Select all
ws.getDocumentProperties( x["uuid"] )
but this doesn't contain the size...

Regards
Holger

Re: Get a documents size

PostPosted:Fri Oct 31, 2014 8:05 am
by jllort
From the object Document you get ActualVersion and there's the document size as a number, to convert on human format can do something like
Code: Select all
private static final String[] UNITS = new String[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };

/**
	 * Format the document size for human readers
	 */
	public static String formatSize(long bytes) {
		for (int i = 6; i > 0; i--) {
			double step = Math.pow(1024, i);
			if (bytes > step)
				return String.format(Locale.ROOT, "%3.1f %s", bytes / step, UNITS[i]);
		}
		
		return Long.toString(bytes) + " " + UNITS[0];
	}

Re: Get a documents size

PostPosted:Mon Nov 03, 2014 10:46 am
by holgrich
Works great, thanks.

Re: Get a documents size

PostPosted:Sat Jan 31, 2015 7:32 pm
by amber14
How shoud I send the params?
An example would be really appreciated. Not necessarily related to Delphi, just the params
Thanks in advance.
Marcelo.

Re: Get a documents size

PostPosted:Sun Feb 01, 2015 1:59 pm
by jllort
if you call getProperties ( api ) -> into you got variable called actualVersion -> what contains the document size as a number. Should be something like:
Code: Select all
long size = ws.getProperties(token, docPath).getActualVersion().getSize();
You can not sent the size parameter, you only can get the stored value. When you change document version, the value is automatically changed.