tags:

views:

46

answers:

4

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

A: 

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
Looks like those are free apps. What do you mean by "limited resources?"
rockinthesixstring
Buth are truly free. Where did I said "limited resources"?
BalusC
A: 

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
The dead should stay burried.
danielkza
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.
rockinthesixstring
I added the "not recommended" before activex :)
k_b
That should not be possible on IE with default config.
BalusC
I tested it, and after several warnings from IE, it worked. Didn't work at all in chrome or firefox.
k_b
A: 

I didn't know about this, but you can have a look at this previous post on SO:

http://stackoverflow.com/questions/1832415/how-validate-file-size-using-html-and-javascript-on-client-side

theIV
Thanks. It worked.
Punit
A: 

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