473,898 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check File Size using JavaScript

Frinavale
9,735 Recognized Expert Moderator Expert
Hi there!

I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript.

I have seen suggested solutions using an ActiveX control to check the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to Internet Explorer.

I cannot check the file size on the web server because IIS throws the following exception before my code is executed:
"System.Web.Htt pException: Maximum request length exceeded"

I realize that the maximum request length can be increased, however according to my application's specifications the files uploaded (images) must be much less than 4MB in size (200K).

Any suggestions or recommendations about how to check the file size using JavaScript are welcome.

Thanks,

-Frinny
Jan 19 '09 #1
3 8287
Frinavale
9,735 Recognized Expert Moderator Expert
I think that what I'm asking is impossible.
I have recently come across an explanation as to why:

Browser security does not allow Scripts to read files from the local hard drive. This means that the input type "File" doesn't have permissions to read files. Therefore, there is no way to use JavaScript to check the file size.



-Frinny
Jan 19 '09 #2
rnd me
427 Recognized Expert Contributor
you can do it in firefox3; file inputs provide a getAsBinary method.

the length of the resulting string is your filesize.

IE can use the activeX stuff.
Jan 19 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Do you know of any solutions for Opera and Safari as well?

I've started looking into a server side fix for this so that it can work in any browser. The main ones I test with are IE, FireFox, Opera and Safari.
Jan 19 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3871
by: vishal | last post by:
hi is there anyway that i can check the size of file on client side before uploading file to server???? suppose the user uploads file of 10 mb then the server will know the size is 10 mb after the file is uploaded to server which wastes the bandwidth so what i want to check is that the server first checks the size of file to upload and if it is o.k. then and then only the file will be uploaded..
3
34750
by: newcomer | last post by:
Is there a way to check if a file exists in Javascript? This is what I'm trying to do: if(thisfile.htm exists) do this else do that
3
8993
by: Matt | last post by:
The user can select a file in the file open dialog using <input type="FILE">, but the user can also enter the full file path in the browse text box manually. My question is if there are JavaScript to check if the file path exists? please advise. thanks!!
2
4743
by: Ruskin | last post by:
I have developed an upload tool, that allows users to upload files (funny that). The asp form object has a 'SizeLimit' property that can be set, to prevent files being uploaded, that are too large. Is there a way in Javascript, to interrogate the file size before the form is posted, so that the validation can be done before trying to post the form. The only information I can find, on file size, relates to images. But any file can be...
2
5486
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the photo size to 1 meg. I would like to check the file size in JavaScript on the page, instead of on the server. Anyone know how I can check the file size in JavaScript?
3
30215
by: puja | last post by:
hi all, In asp.net 2.0 there is a limit on file size upload of 4MB. I know this limit can be increased in web.config file. Is there any way to check the file size before upload ? if user is trying to upload file size more than 4MB then just display a message that file size is too big and can't be uploaded. thanks
2
3485
by: Mike | last post by:
Hello, I have a page that uploads a file. It has a form and uses SELF to process the file the second time around. I have MAX_FILE_SIZE set. The problem is, if the file is too big I cant check $FILE until it comes back.Which could be a while.(which the server sets to 0). I want to check it with javascript if possible. If I try to upload a 20 gig file the customer wont know its too big for hours. Help
13
4829
by: marfola | last post by:
Iím trying to find the file size using javascript, before it get uploaded into the server using the following Javascript (I donít want to use ActiveX because of compatibility problem). function imageSize (pathField, previewName) { var str = ''; var path = pathField.value; document.src = 'file://'+path.replace(/\\/gi,'/'); var img = new Image(); img.src = 'file://'+path.replace(/\\/gi,'/'); var size_pic =...
4
3886
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
0
9840
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10857
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10483
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3305
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.