Get file size before upload using jquery
File uploading functionality is generally used by the developers. Before uploading file on the server, to know the size of file is a good practice. By knowing file size, we can restrict the end user to upload large size files on the server since we have limited space on the server. We should check uploaded file size on server side as well client side. In this article I am going to expose how you can get size of file before uploading on client side using JQuery. For more help refer the article Asp.Net asynchronous file upload using jquery.
Example to get file size before upload using JQuery
Example to get file size before upload in Asp.Net using JQuery
Using above defined function "GetFileSize", we can also get file size in Asp.net also like as :
<form id="form1" runat="server"> <asp:FileUpload ID="fUpload" runat="server" /> <asp:Button ID="btnGetSize" runat="server" Text="Button" OnClientClick="GetFileSize('fUpload');" /> </form>
Above example will work on all browsers including IE, FF, Chrome, Safari, Opera etc.
In this article I try to expose how you can get size of file before uplaoding. I hope after reading this article you will be able to use this trick in your code. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.
Take our free skill tests to evaluate your skill!
In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.