I am using Spring Boot to test a upload functionality, and getting 'Required MultipartFile parameter 'file' is not present' error. when it deployed external tomcat server. but it properly works with spring boot tomcat plugin Following are the 1) JSP, 2) Controller 3) Config property
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)
@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)
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;
}