As I set the maximum file upload limit, I get
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 2097152 bytes
when downloading a file. This gives 500 errors for my api, I have to handle this error and return a response in JSON , and not an error, as indicated in ErrorController
I want to catch this exception and give a JSON response not ErrorPage .
@RequestMapping(value="/save",method=RequestMethod.POST) public ResponseDTO<String> save(@ModelAttribute @Valid FileUploadSingleDTO fileUploadSingleDTO,BindingResult bindingResult)throws MaxUploadSizeExceededException { ResponseDTO<String> result=documentDetailsService.saveDocumentSyn(fileUploadSingleDTO, bindingResult); return result; }
DTO, which accepts the document as follows
public class FileUploadSingleDTO { @NotNull private Integer documentName; private Integer documentVersion; @NotNull private MultipartFile file; }
source share