1

I am uploading a file in an ASP.NET application, I need to get the file size for some client side validation. Following the advice I found here. I have something like this:

in aspx:

<td class="form_input_bold">
            <asp:FileUpload Width="80%" ID="fuUploadFile" CssClass="button" runat="server" Font-Names="Verdana" />                
        </td>

And in Javascript:

var inputFile = document.getElementById('ctl00_ContentPlaceHolder1_fuUploadFile');
alert("File size: " + inputFile.size);

Now for some reason, when I try to upload a 50 MB file, inputFile.size returns 20. Can anyone tell why this is? ASP.NET is getting the correct size server side..

4
  • You are using a modern browser, right? Commented Oct 21, 2013 at 19:14
  • @JoeEnos Yes, I tried the latest versions of Chrome and Firefox. Commented Oct 21, 2013 at 19:15
  • Not sure if this is your real code, but if so, you should modify it so that you're not hard-coding the client control ID - instead do document.getElementById("<%= fuUploadFile.ClientID %>"), which will render the way you have it. Commented Oct 21, 2013 at 19:24
  • 2
    @JoeEnos Its not hard coded, but it does use my company's internal Javascript API and I don't want to give anyone a migraine by posting that here.. Commented Oct 21, 2013 at 19:28

1 Answer 1

2

The file's size is found in the element of the files array of the input control.

var numBytes = document.getElementById("fu1").files[0].size;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.