问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/14075287/does-maxpostsize-apply-to-multipart-form-data-file-uploads