[英]Tomcat : Required request part 'file' is not present
I am using Spring Boot to test a upload functionality, and getting 'Required MultipartFile parameter 'file' is not present' error.我正在使用 Spring Boot 来测试上传功能,并收到“Required MultipartFile parameter 'file' is not present”错误。 when it deployed external tomcat server.
当它部署外部 tomcat 服务器时。 but it properly works with spring boot tomcat plugin Following are the 1) JSP, 2) Controller 3) Config property
但它与spring boot tomcat插件一起正常工作以下是1)JSP,2)控制器3)配置属性
1) 1)
<form id="initialUploadForm" action="${root}/upload/uploadCapFile" enctype="multipart/form-data" method="post">
<table align="left" width="50%" cellspacing="0" cellpadding="5"
border="0" class="formTable">
<tr>
<td><label class="">Add Cap File : </label></td>
<td><input type="file" name="file" style="width:100%;"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td><input class="btn btn-success" type="submit"
value="Upload Data" id="btnInitialUpload"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
2) 2)
@RequestMapping(value = "uploadCapFile", method = RequestMethod.POST)
ModelAndView uploadCapFileData(@RequestParam("file") MultipartFile file, Model model) {
try {
if (log.isDebugEnabled()) log.debug("UploadController calling : ");
System.out.println("File Name : " + file.getOriginalFilename());
long lStartTime = new Date().getTime();
if (!file.isEmpty()) {
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
if (extension.equals(Constants.FILE_FORMAT)) {
File convFile = convertFile(file);
InputStream in = new FileInputStream(convFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder out = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
}
if (isProdUpdate == 1) {
hotelService.updateAgentMarkup(out.toString());
} else {
hotelService.updateHotelData(out.toString());
}
} else {
log.error("Invalid File Format ! File Format is :" + Constants.FILE_FORMAT);
}
} else {
log.error("File is missing ! Can not be Process");
}
long lEndTime = new Date().getTime();
long output = TimeUnit.MILLISECONDS.toSeconds(lEndTime - lStartTime);
processingTime = String.valueOf(output);
} catch (IOException e) {
log.error("Error occurred while calling the UploadController : " + e);
} catch (TalcacheException e) {
log.error("Error occurred while calling the UploadController : " + e.getErrorMsg());
} catch (Exception e) {
log.error("Error occurred while calling the UploadController : " + e);
}
}
3) 3)
spring.servlet.multipart.enabled=true
spring.servlet.multipart.file-size-threshold=5KB
spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=215MB
Put this code into config file将此代码放入配置文件
@Bean
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(-1);
return multipartResolver;
}
尝试在方法签名中添加multipart/form-data
。
@RequestMapping(value = "uploadCapFile", method = RequestMethod.POST,headers = "content-type=multipart/form-data")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.