469,587 Members | 2,659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,587 developers. It's quick & easy.

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 2002
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dave | last post: by
3 posts views Thread by Sorin Dolha | last post: by
2 posts views Thread by Tom Wells | last post: by
reply views Thread by SEMIH DEMIR | last post: by
1 post views Thread by Marko Vuksanovic | last post: by
5 posts views Thread by camphor | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.