Google 微软 Apple Java 无人驾驶 人工智能 大数据 阿里巴巴 特斯拉 Facebook VR/AR 安全 手机 亚马逊 机器人 云计算

Tomcat 通过表单上传文件 maxPostSize 控制上传大小

tomcat/java/org/apache/catalina/connector/Connector.java

/**
 
* Maximum size of a POST which will be automatically parsed by the
 
* container. 2MB by default.
 
*/
 
protected int maxPostSize = 2 * 1024 * 1024;

 

tomcat/java/org/apache/catalina/connector/Request.java

 

int maxPostSize = getConnector().getMaxPostSize();
 
int postSize = 0;
 
Charset charset = getCharset();
 
for (FileItem item : items) {
 
ApplicationPart part = new ApplicationPart(item, location);
 
parts.add(part);
 
if (part.getSubmittedFileName() == null) {
 
String name = part.getName();
 
String value = null;
 
try {
 
value = part.getString(charset.name());
 
} catch (UnsupportedEncodingException uee) {
 
// Not possible
 
}
 
if (maxPostSize >= 0) {
 
// Have to calculate equivalent size. Not completely
 
// accurate but close enough.
 
postSize += name.getBytes(charset).length;
 
if (value != null) {
 
// Equals sign
 
postSize++;
 
// Value length
 
postSize += part.getSize();
 
}
 
// Value separator
 
postSize++;
 
if (postSize > maxPostSize) {
 
parameters.setParseFailedReason(FailReason.POST_TOO_LARGE);
 
throw new IllegalStateException(sm.getString(
 
“coyoteRequest.maxPostSizeExceeded”));
 
}
 
}
 
parameters.addParameter(name, value);
 
}
 
}
 

 

点赞 0 打赏

我要评论