Another File Upload question

G

Guest

Hi there,
I've been reading all I could find on the control 'input type=file' and all
the trouble that it comes when uploading large binary files (>4MB) to a DB
server or server path.

I've seen plenty of examples about it, and they all agree that to make
possible the upload of those files, it's mandatory to change the web.config
(or machine.config) for the maxRequestLength attribute of the <httpRuntime>
element.

What I'd need though, is a way for NOT allowing content larger than those
4MB to be uploaded. I've tryed the following on my code, but it's not
working (probably because I've also read that when submitting the webform,
the content is already sent to the server, thus if you send 50MB you'll have
to wait until the server returns an error)

if( FileInputAttachment.PostedFile.ContentLength ) > 1024
{
//change a label text to display an error
}

Is there a way of querying for the PostedFile.ContentLength BEFORE posting
the data to the server? This way I could warn the users not to upload files
larger than a MB or so...

Thanks!!
 
K

Kevin Spencer

Hi ricardo,

Wiothout some sort of ActiveX control or Java applet on the client side,
there is no way to determine the length of the file prior to upload. The
input only contains the path to the file to be uploaded on the client.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven
 
G

Guest

I feared so...Do you know of any third party (and hopefully free) ActiveX
control I could use?
 
K

Kevin Spencer

Sorry ricardo. But Google it. You never know.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven
 
J

Joerg Jooss

ricardo said:
Hi there,
I've been reading all I could find on the control 'input type=file'
and all the trouble that it comes when uploading large binary files
(>4MB) to a DB server or server path.

I've seen plenty of examples about it, and they all agree that to
make possible the upload of those files, it's mandatory to change the
web.config (or machine.config) for the maxRequestLength attribute of
the <httpRuntime> element.

What I'd need though, is a way for NOT allowing content larger than
those 4MB to be uploaded. I've tryed the following on my code, but
it's not working (probably because I've also read that when
submitting the webform, the content is already sent to the server,
thus if you send 50MB you'll have to wait until the server returns an
error)

if( FileInputAttachment.PostedFile.ContentLength ) > 1024
{
//change a label text to display an error
}

Is there a way of querying for the PostedFile.ContentLength BEFORE
posting the data to the server? This way I could warn the users not
to upload files larger than a MB or so...

HTTP expectations (status code 100) are meant for that purpose,
although it still requires a (cheap) roundtrip. And it also requires
your web clients to play along nicely -- I have no idea if IE or
Firefox even use this header before posting (large) entities.
System.Net.HttpWebRequest does by default.

Cheers,
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top