Any elegant solution for managing upload file size?

B

Braky Wacky

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
 
B

Benjamin Bittner

Hallo Braky
Braky Wacky said:
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
 
T

Trevor Benedict R

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!
 
B

Braky Wacky

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
 
K

Kevin Spencer

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.
 
B

Braky Wacky

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
 
D

Daniel R. Tobias

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.
 
S

spalding

Braky said:
*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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top