File size of an uploaded file

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

File size of an uploaded file

#1

Postby Vircos » Mon Mar 21, 2011 2:54 pm

Hi all,

Is it possible to determine the file size of an uploaded file?

Kind regards,
Vircos
0 x
What's the meaning of Justice...

ehmd
Ebase User
Posts: 53
Joined: Thu Sep 13, 2007 9:02 am
Contact:

#2

Postby ehmd » Tue Mar 22, 2011 8:39 am

Have a look at this link which should give you some options for a custom function :-

http://stackoverflow.com/questions/1165 ... fficiently

regards,

Mark
0 x

DannyWild
Ebase User
Posts: 4
Joined: Wed Jun 20, 2012 6:19 am

#3

Postby DannyWild » Thu Aug 22, 2013 6:56 am

Is it now, many year later, posible with a javascript function to get a file size? It would be great if it's posible.

Kind regards,
Sjoerd
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#4

Postby Jon » Thu Aug 22, 2013 8:03 am

Here's a Javascript function to get file length. Returns -1 if the file doesn't exist:

Code: Select all

function getFileLength(path)
{
	if (path)
	{
		var f = new java.io.File(path);
		if (f && f.isFile())
		{
			return f.length();
		}
	}
	return -1;
}
0 x

DannyWild
Ebase User
Posts: 4
Joined: Wed Jun 20, 2012 6:19 am

#5

Postby DannyWild » Thu Aug 22, 2013 11:21 am

Thanks that function works for me.

The only thing (if someone wants to use it) is to keep in mind to add backslashes to the filename to escape the backslashes used.
For example
D:\folder\image.jpg must be
D:\\folder\\image.jpg

I've used this funtion to do that:

Code: Select all

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
0 x


Who is online

Users browsing this forum: No registered users and 18 guests