473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Any elegant solution for managing upload file size?

Hello,

I have an ASP.NET webpage that uses an instance of
System.Web.UI.HtmlControls.HtmlInputFile for uploading files to our
server. I came across the documentation at MSDN for upping the
filesize limit, once I saw the behavior of the page bombing with files
bigger than 4 MB. So far so good.

But the situation I'm coming across is that there doesn't seem to be
an elegant way of recovering from a user attempting to upload files
that are too big. I want a way to be able to handle this
programmatically, rather than dropping some custom error page in place
for HTTP 500 errors. The best I was able to come up with was to
actually set the httpRuntime maxRequestLength up to some ridiculously
high value, then check against the actual limit I want against the
PostedFile.ContentLength value in the event handler for the
HtmlInputFile. But it seems like the file actually gets uploaded
before I can check this value, completely defeating the purpose for
doing that in the first place.

Has anyone come up with a solution for managing the behavior of
attempting to upload files that are too large in ASP.NET? I'm at a
point where I'm thinking I'll need to develop an ActiveX control, or
leverage one from a third party, just to be able to manage this use
case.

Any thoughts/suggestions would be most welcome.

Thanks,
Kevin
Nov 18 '05 #1
8 2134
A lot of people end up going for a 3rd party component for uploading large
files. The vendors use techniques that offload the processing and don't
choke ASP.NET.

I did a review of this product and found it pretty good:

http://fileup.softartisans.com/default.aspx?PageID=131

"Braky Wacky" <he***********@hotmail.com> wrote in message
news:4e*************************@posting.google.co m...
Hello,

I have an ASP.NET webpage that uses an instance of
System.Web.UI.HtmlControls.HtmlInputFile for uploading files to our
server. I came across the documentation at MSDN for upping the
filesize limit, once I saw the behavior of the page bombing with files
bigger than 4 MB. So far so good.

But the situation I'm coming across is that there doesn't seem to be
an elegant way of recovering from a user attempting to upload files
that are too big. I want a way to be able to handle this
programmatically, rather than dropping some custom error page in place
for HTTP 500 errors. The best I was able to come up with was to
actually set the httpRuntime maxRequestLength up to some ridiculously
high value, then check against the actual limit I want against the
PostedFile.ContentLength value in the event handler for the
HtmlInputFile. But it seems like the file actually gets uploaded
before I can check this value, completely defeating the purpose for
doing that in the first place.

Has anyone come up with a solution for managing the behavior of
attempting to upload files that are too large in ASP.NET? I'm at a
point where I'm thinking I'll need to develop an ActiveX control, or
leverage one from a third party, just to be able to manage this use
case.

Any thoughts/suggestions would be most welcome.

Thanks,
Kevin


Nov 18 '05 #2
Hallo Braky
"Braky Wacky" <he***********@hotmail.com> schrieb im Newsbeitrag
news:4e*************************@posting.google.co m...
Hello,

I have an ASP.NET webpage that uses an instance of
System.Web.UI.HtmlControls.HtmlInputFile for uploading files to our
server. I came across the documentation at MSDN for upping the
filesize limit, once I saw the behavior of the page bombing with files
bigger than 4 MB. So far so good.

But the situation I'm coming across is that there doesn't seem to be
an elegant way of recovering from a user attempting to upload files
that are too big. I want a way to be able to handle this
programmatically, rather than dropping some custom error page in place
for HTTP 500 errors. The best I was able to come up with was to
actually set the httpRuntime maxRequestLength up to some ridiculously
high value, then check against the actual limit I want against the
PostedFile.ContentLength value in the event handler for the
HtmlInputFile. But it seems like the file actually gets uploaded
before I can check this value, completely defeating the purpose for
doing that in the first place.

Has anyone come up with a solution for managing the behavior of
attempting to upload files that are too large in ASP.NET? I'm at a
point where I'm thinking I'll need to develop an ActiveX control, or
leverage one from a third party, just to be able to manage this use
case.

Any thoughts/suggestions would be most welcome.

Thanks,
Kevin


The problem is, that an input type=file, posts the file directly after
submitting to the http header. and it really posts the whole file as binary
to the header, not a reference to it. this is because of some security
reasons. it makes it impossible to do anything with the file before it
reaches the server. if input would post an reference to the file, and you
would programmatically start the upload, you could change the reference to
any file on the clients machine and upload this.

regards benni
Nov 18 '05 #3
I have a small warning next to the upload button as to the Max File
Size. If they go past that then they know why they have the error
Screen.

Regards,

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
Thanks, everyone, for your responses. It doesn't look like there's
any (IMO) reasonable way to handle this out of the box. That's
unfortunate. It would be nice if there was some object exposed on the
client side that could give basic file information (name, size, maybe
ContentType, etc.). Ultimately, I'd like to check this condition on
the client, before any roundtrips are made to the server. Ah well,
I'll keep searching.

Thanks again,
Kevin
Trevor Benedict R <tr********@yahoo.com> wrote in message news:<eZ**************@TK2MSFTNGP09.phx.gbl>...
I have a small warning next to the upload button as to the Max File
Size. If they go past that then they know why they have the error
Screen.

Regards,

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
If you think that something should be changed on the client-side, I would
suggest contacting the W3C. Microsoft has no control over HTML standards.
The W3C is always open to suggestions.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Braky Wacky" <he***********@hotmail.com> wrote in message
news:4e**************************@posting.google.c om...
Thanks, everyone, for your responses. It doesn't look like there's
any (IMO) reasonable way to handle this out of the box. That's
unfortunate. It would be nice if there was some object exposed on the
client side that could give basic file information (name, size, maybe
ContentType, etc.). Ultimately, I'd like to check this condition on
the client, before any roundtrips are made to the server. Ah well,
I'll keep searching.

Thanks again,
Kevin
Trevor Benedict R <tr********@yahoo.com> wrote in message

news:<eZ**************@TK2MSFTNGP09.phx.gbl>...
I have a small warning next to the upload button as to the Max File
Size. If they go past that then they know why they have the error
Screen.

Regards,

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6
I don't necessarily expect Microsoft to have the answer to this
problem, and was more hoping that someone might have a workaround that
functions a little better than the solutions I've found so far. And I
do appreciate the feedback from those who have offered suggestions.

But to talk about Microsoft's hands being tied due to having no
control over HTML standards is more than just a little disingenuous,
wouldn't you say? Or were you not around for Microsoft's myriad
changes and deviations from the W3C-approved HTML standard in the
early days, to say nothing of any of the other examples (which are too
numerous to name here) of Microsoft forging ahead with their own
version of standards ahead of the versions put forth by standards
bodies? I'm not arguing for or against Microsoft's policy of doing
this; whether or not those decisions were/are legitimate is a
completely different argument altogether. But the fact that they've
historically made those decisions renders false your assertion that
they do not have the ability or willingness to do so.

Kevin
"Kevin Spencer" <ks******@takempis.com> wrote in message news:<Ox**************@TK2MSFTNGP12.phx.gbl>...
If you think that something should be changed on the client-side, I would
suggest contacting the W3C. Microsoft has no control over HTML standards.
The W3C is always open to suggestions.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Braky Wacky" <he***********@hotmail.com> wrote in message
news:4e**************************@posting.google.c om...
Thanks, everyone, for your responses. It doesn't look like there's
any (IMO) reasonable way to handle this out of the box. That's
unfortunate. It would be nice if there was some object exposed on the
client side that could give basic file information (name, size, maybe
ContentType, etc.). Ultimately, I'd like to check this condition on
the client, before any roundtrips are made to the server. Ah well,
I'll keep searching.

Thanks again,
Kevin
Trevor Benedict R <tr********@yahoo.com> wrote in message

news:<eZ**************@TK2MSFTNGP09.phx.gbl>...
I have a small warning next to the upload button as to the Max File
Size. If they go past that then they know why they have the error
Screen.

Regards,

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #7
he***********@hotmail.com (Braky Wacky) wrote in message news:<4e**************************@posting.google. com>...
But to talk about Microsoft's hands being tied due to having no
control over HTML standards is more than just a little disingenuous,
wouldn't you say?


Well, any "solution" Microsoft might happen to implement at the client
level would have no effect on me, since I browse with Mozilla. A W3C
standard, however, would have a good chance of being implemented by
the Mozilla developers and thus would let me benefit from it.

--
Dan
Nov 18 '05 #8

Braky Wacky wrote:
*Hello,

I have an ASP.NET webpage that uses an instance of
System.Web.UI.HtmlControls.HtmlInputFile for uploading files to our
server. I came across the documentation at MSDN for upping the
filesize limit, once I saw the behavior of the page bombing wit
files
bigger than 4 MB. So far so good.

But the situation I'm coming across is that there doesn't seem to be
an elegant way of recovering from a user attempting to upload files
that are too big. I want a way to be able to handle this
programmatically, rather than dropping some custom error page i
place
for HTTP 500 errors. The best I was able to come up with was to
actually set the httpRuntime maxRequestLength up to som
ridiculously
high value, then check against the actual limit I want against the
PostedFile.ContentLength value in the event handler for the
HtmlInputFile. But it seems like the file actually gets uploaded
before I can check this value, completely defeating the purpose for
doing that in the first place.

Has anyone come up with a solution for managing the behavior of
attempting to upload files that are too large in ASP.NET? I'm at a
point where I'm thinking I'll need to develop an ActiveX control, or
leverage one from a third party, just to be able to manage this use
case.

Any thoughts/suggestions would be most welcome.

Thanks,
Kevin *


It's not the most elegant solution although it does not involv
throwing an error (and with a bit of tweaking could probably become
viable solution).

I have implemented an HTTPHandler that checks th
HttpContext.Request.ContentLength value (which is available at th
beginning of the client request).
If this value is larger than my max. upload size, I set a flag in th
HttpContext.Cache (although you could set this in the Application o
Session array if you preferred).

When the form is posted, clientside javascript opens a second windo
that contains a very simple ASPX page. The page checks the flag tha
was set in the HttpContext.Cache and if the file is too big, the pag
renders some clientside javascript that redirects the parent pag
(through the use of window.opener.document.location.href).

The page I redirect to tells the user that the file they tried t
upload was too large right after the form has started to post (and a
the same time cancels the previous Request).

This does require a trip to the server, but it stops the form fro
uploading the full file and the user can find out almost immediatel
that the file they attempted to upload is too large
-
spaldin
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11735
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
21
4808
by: dub | last post by:
Hello web folks... I've been desigining web pages for 13 years using my trusty text editor (UltraEdit) and in depth knowledge of HTML. I'm truly a text editor ninja at this point. I am frequently...
3
1987
by: Sorin Dolha | last post by:
Hello, We intend to create an ASP.NET-based Web application (hosted on Internet Information Services, or IIS) and one feature of the application needs to allow the end user to upload photos to...
2
6045
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
0
4736
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
1
2114
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
9
20874
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
32
1993
by: r.z. | last post by:
class vector3 { public: union { float data; struct { float x, y, z; };
5
3260
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
0
6991
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...
0
7160
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,...
0
7196
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...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7373
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...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.