"Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes."
I have tried the following code in my files but every time I am getting the error
1. application.property
server.tomcat.max-swallow-size=100MB
server.tomcat.max-http-post-size=100MB
spring.servlet.multipart.enabled=true
spring.servlet.multipart.fileSizeThreshold=100MB
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
I have also tried
spring.servlet.multipart.maxFileSize=100MB
spring.servlet.multipart.maxRequestSize=100MB
2. The belove is my file uploading code
public RestDTO uploadFile(MultipartFile file, String subPath) {
if (file.isEmpty()) {
return new RestFailure("Failed to store empty file");
}
try {
String fileName = new Date().getTime() + "_" + file.getOriginalFilename();
String filePath = uploadPath + subPath + fileName;
if (Objects.equals(file.getOriginalFilename(), "blob")) {
filePath += ".png";
fileName += ".png";
}
File uploadDir = new File(uploadPath + subPath);
if (!uploadDir.exists()) {
uploadDir.mkdirs();
}
FileOutputStream output = new FileOutputStream(filePath);
output.write(file.getBytes());
LOGGER.info("File path : " + filePath);
MediaInfoDTO mediaInfoDTO = getThumbnailFromVideo(subPath, fileName);
String convertedFileName = convertVideoToMP4(subPath, fileName);
System.out.println("---------------->" + convertedFileName);
return new RestData<>(new MediaDetailDTO(mediaInfoDTO.getMediaPath(), convertedFileName,
mediaInfoDTO.getMediaType(), mediaInfoDTO.getMediaCodec(), mediaInfoDTO.getWidth(),
mediaInfoDTO.getHeight(), mediaInfoDTO.getDuration()));
} catch (IOException e) {
LOGGER.info("Can't upload file: " + e.getMessage());
return new RestFailure("Failed to store empty file");
}
}
but every time I got the same exception.
Comment From: wilkinsona
The configuration properties that you have shared above work for me with Spring Boot 2.2.5. Setting the following is sufficient:
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
Note that these configuration properties will only take effect if you are using the auto-configured MultipartConfigElement
bean. If you have defined your own, they will be ignored. If this doesn't help, please provide a complete sample that reproduces the problem in a zip attached to this issue or in a separate GitHub repository and we can take another look.
Comment From: wilkinsona
I see that you have also asked this on Stack Overflow. Given that I cannot reproduce the problem and to avoid any further duplication of effort, I'm going to close this issue in favour of your Stack Overflow question.