Crediting @james-kleeh for this head start;
But I could only get this working on Grails 4.0.0.M2 when I extend the StandardServletMultipartResolver
implementation which is what is used as default. Then the maxFileSize limits continue to be resolved from config (yaml).
public class MyMultipartResolver extends StandardServletMultipartResolver {
static final String FILE_SIZE_EXCEEDED_ERROR = "fileSizeExceeded"
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) {
try {
return super.resolveMultipart(request)
} catch (MaxUploadSizeExceededException e) {
request.setAttribute(FILE_SIZE_EXCEEDED_ERROR, true)
return new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap<String, MultipartFile>(), new LinkedHashMap<String, String[]>(), new LinkedHashMap<String, String>());
}
}
}
With the following in resources.groovy;
// catch exception when max file size is exceeded
multipartResolver(MyMultipartResolver)
You need to subsequently check for the FILE_SIZE_EXCEEDED_ERROR attribute in the controller and handle accordingly.