Is it possible to get the file size of the file being submitted before the upload actually starts on Javascript?
Asked
Active
Viewed 264 times
4 Answers
0
No, that's not reliably possible due to security restrictions. You'll need Flash or Java Applet for this. If your intent is just to have a progress bar, have a look at Uploadify or SWFUpload

BalusC
- 1,082,665
- 372
- 3,610
- 3,555
-
Looks like those are free apps. What do you mean by "limited resources?" – Chase Florell Jun 05 '10 at 00:52
-
Buth are truly free. Where did I said "limited resources"? – BalusC Jun 05 '10 at 12:14
0
Looks like you need the not recommended activex (source: http://www.jguru.com/faq/view.jsp?EID=330134):
<html>
<head>
<script language="JavaScript">
function A()
{
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + " bytes");
}
</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE" onClick="A();">
</form>
</body>
</html>

k_b
- 2,470
- 18
- 9
-
3
-
Can I down vote on principle? Seriously... I know you're trying to be helpful, but ActiveX? I don't think so. Java or Flash will work cross browser which is a nice feature. Some people say Java should die but there are still "some" good uses for it. – Chase Florell Jun 05 '10 at 00:41
-
-
-
I tested it, and after several warnings from IE, it worked. Didn't work at all in chrome or firefox. – k_b Jun 05 '10 at 00:56
0
I didn't know about this, but you can have a look at this previous post on SO:
how validate file size using HTML and Javascript on client side
0
The relevant feature (The HTML5? File API or what to call it) that is needed isn't fully specified yet. Mozillas implementation can be read at the mozilla developer center

azatoth
- 2,379
- 15
- 18