Jump to content

Limit upload filesize dynamically for Java app?


Recommended Posts

Need some advice from anybody here who might be a networking/Java guru.

 

I'm working on a Java app that uses Apache/Tomcat and to which the users sometimes upload files. I know that Apache can be configured with a maximum file upload size, but this application needs to allow some users to upload certain file sizes and others a different size.

 

The request header contains a content-length attribute that can be used to check the request size. The problem is that by the time the servlet is processing the request and can look at this information, the entire file has been uploaded. So a user might upload a huge file and then, after waiting, be told that his file is too big and has been discarded. What I'd really like is to peek at the request header as the request first starts coming in and close the connection if the file is too big.

 

I considered writing a custom Valve for Tomcat, but it looks to me like a Valve also does not process a request until the entire request has been received.

 

My next thought is to customize some kind of proxy between Apache and Tomcat. Is there any way that a Java component can be put in the pipeline to sniff out request headers and parse the content-length? (I'm assuming that Apache pipes requests through to Tomcat as they come in, rather than waiting for the entire request body and then passing it on. I think that's a reasonable assumption but really don't know.)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...