Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does maxPostSize apply to multipart/form-data file uploads

I have a webapp on a Tomcat server that allows files to be uploaded. There is a limit on the size of a file upload, and I'd like that limit to be enforced preemptively (ie, once you cross the limit, the file upload fails, rather than transferring the whole file, checking that it's too big and then sending an error).

I tried to do this by add maxPostSize="1000" to the connector section in the relevant connector in server.xml, but I can still upload larger files.

I've seen a post indicating that maxPostSize only works for a specific content type.

So my question is whether what I'm doing is supposed to work. Is my limit not having an effect because I've configured Tommcat wrong, or because that field just isn't applied to the kind of post that I'm doing?

like image 483
BostonJohn Avatar asked Dec 28 '12 20:12

BostonJohn


People also ask

How does multipart file upload work?

Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts.

How do I upload a multipart form data?

Follow this rules when creating a multipart form: Specify enctype="multipart/form-data" attribute on a form tag. Add a name attribute to a single input type="file" tag. DO NOT add a name attribute to any other input, select or textarea tags.

What is multi part form data?

Multipart form data: The ENCTYPE attribute of <form> tag specifies the method of encoding for the form data. It is one of the two ways of encoding the HTML form. It is specifically used when file uploading is required in HTML form. It sends the form data to server in multiple parts because of large size of file.


1 Answers

There is a very informative discussion of this topic here.

As I understand it, Tomcat only enforces that limit if the content type is application/x-www-form-urlencoded. For multiparts you'll have to read the stream yourself and enforce the limit yourself. A great tool for working with multipart data is Apache FileUpload.

like image 124
Tony R Avatar answered Oct 01 '22 02:10

Tony R