Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 25th, 2006, 04:02 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Verifying uploaded File Size in Client-side

Hi All,

   We are using VS.net 2003 with VB.net. In my application, we have used HTMLInput control to upload a file to the web server.

   We have restricted the user from uploading file more than 4MB. So it will give message. If we upload more than 4MB it takes much time to upload fully into server and give message.

   Instead of checking the file size in web server, checking the size - from clientside - even before upload to server - would be better.

   Anything in Javascript or some other idea? Please explain me clearly.

   If you have any idea pls share with me. It would b very much useful. Thank you.

Usha


  #2 (permalink)  
Old August 25th, 2006, 06:46 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I don't know of any JS that will allow you to do this but, I think, your process is flawed. Using a client side JavaScript requires that the client has JavaScript enabled on their browser, what happens if a user navigates to your website and tries to upload a 10mb file and they have JavaScript disabled?

Also .NET, by default, will only accept 4mb file uploads unless you explicitly go in and change this through the web.config file.

Another thing to considers: .NET 1.1 has extremely poor memory management when uploading files like this. If say, for example, you were to upload a 40mb file, the file will be passed into the aspnet_wp.exe process where it would then be saved to disk.

aspnet_wp.exe consumes 40mb of memory on the server when that file is passed in and instead of automatically relasing that memory when it is done saving, it only releases a little if at all. What eventually happens is that aspnet_wp.exe consumes 80% of server memory and the process is automatically restarted... which can cause you app to fail.

My suggestion would be to look into an HttpModule/handler which will stream the data straight to disk and bypass loading the file into the worker account.

hth

"The one language all programmers understand is profanity."
  #3 (permalink)  
Old August 28th, 2006, 12:22 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank U for ur reply.

Assume that JavaScript is enabled in the browser. Can you give some solution in this case ?

V have allowed the user to upload only 4MB but if the user select a file which is more than 4MB v would like to stop the user from the client-side itself. It saves the upload time for the user.

Ur suggestion would be highly useful.

  #4 (permalink)  
Old August 28th, 2006, 07:47 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Like i said, I don't know of any JS that can do this because what you are attempting to do is read the users harddrive and read the bytes of X file.

Also, the time you would save is probably a fraction of a second as you can immeadeatlely read the length of the postedfile.length and send a message back to the user telling them of the size requirements.


"The one language all programmers understand is profanity."
  #5 (permalink)  
Old August 30th, 2006, 04:23 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok.
But if the user tries to upload 3.5MB file then it takes much time to upload. It depends upon the n/w speed. But still the user needs to wait for longtime even the file cud not be loaded due to its size restriction.

Thats y I need solution to find the file-size which is being uploaded.

Thank U.
  #6 (permalink)  
Old August 30th, 2006, 07:13 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

JavaScript cannot access the filesystem to do this. The closest thing you would be able to do is to write a function in JScript that would make a call to the ActiveX object and then you may be able to do this; now there are multiple caveats here: 1)The browser would most certainly need to be IE 2)The user would of blatenlty had to ignore MS's security warning about disabling ActiveX controls for this to work.

So, if i were to navigate to your site and try to do the file upload, your process is going to fail because I have activeX objects disabled and almost NEVER will allow them from third parties.

"The one language all programmers understand is profanity."


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i determine size of file being uploaded? kaos_frack Beginning PHP 3 January 10th, 2007 03:48 PM
File size on customer side vincentvdm Javascript How-To 2 August 25th, 2003 04:16 PM
File size on client side vincentvdm Classic ASP Basics 0 August 25th, 2003 02:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.