0

Is it possible to get the file size of the file being submitted before the upload actually starts on Javascript?

Punit
  • 37
  • 2
  • 6

4 Answers4

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
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
    The dead should stay burried. – danielkza Jun 05 '10 at 00:36
  • 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 added the "not recommended" before activex :) – k_b Jun 05 '10 at 00:46
  • That should not be possible on IE with default config. – BalusC Jun 05 '10 at 00:51
  • 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

Community
  • 1
  • 1
theIV
  • 25,434
  • 5
  • 54
  • 58
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