use of cn.taketoday.web.bind.NotMultipartRequestException in project today-framework by TAKETODAY.
the class ServletMultipartRequest method parseRequest.
private MultiValueMap<String, MultipartFile> parseRequest(HttpServletRequest request) {
try {
Collection<Part> parts = request.getParts();
LinkedMultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<>(parts.size());
for (Part part : parts) {
String headerValue = part.getHeader(HttpHeaders.CONTENT_DISPOSITION);
ContentDisposition disposition = ContentDisposition.parse(headerValue);
String filename = disposition.getFilename();
files.add(part.getName(), new ServletPartMultipartFile(part, filename));
}
return files;
} catch (IOException e) {
throw new MultipartException("MultipartFile parsing failed.", e);
} catch (ServletException e) {
throw new NotMultipartRequestException("This is not a multipart request", e);
} catch (Throwable ex) {
String msg = ex.getMessage();
if (msg != null && msg.contains("size") && msg.contains("exceed")) {
throw new MaxUploadSizeExceededException(-1, ex);
}
throw new MultipartException("Failed to parse multipart servlet request", ex);
}
}
use of cn.taketoday.web.bind.NotMultipartRequestException in project today-infrastructure by TAKETODAY.
the class ServletMultipartRequest method parseRequest.
private MultiValueMap<String, MultipartFile> parseRequest(HttpServletRequest request) {
try {
Collection<Part> parts = request.getParts();
LinkedMultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<>(parts.size());
for (Part part : parts) {
String headerValue = part.getHeader(HttpHeaders.CONTENT_DISPOSITION);
ContentDisposition disposition = ContentDisposition.parse(headerValue);
String filename = disposition.getFilename();
if (filename != null) {
if (filename.startsWith("=?") && filename.endsWith("?=")) {
filename = MimeDelegate.decode(filename);
}
files.add(part.getName(), new ServletPartMultipartFile(part, filename));
}
}
return files;
} catch (IOException e) {
throw new MultipartException("MultipartFile parsing failed.", e);
} catch (ServletException e) {
throw new NotMultipartRequestException("This is not a multipart request", e);
} catch (Throwable ex) {
String msg = ex.getMessage();
if (msg != null && msg.contains("size") && msg.contains("exceed")) {
throw new MaxUploadSizeExceededException(-1, ex);
}
throw new MultipartException("Failed to parse multipart servlet request", ex);
}
}
Aggregations