does maxPostSize apply to multipart/form-data file uploads

假装没事ソ 提交于 2019-12-19 06:04:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!