By default, Spring REST allows only POST for multipart request. To allow multipart payload for PUT request, you should create 'MultipartResolver' bean like below.
Previous
Next
Home@Bean
public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver() {
@Override
public boolean isMultipart(HttpServletRequest request) {
String method = request.getMethod().toLowerCase();
//By default, only POST is allowed. Since this is an 'update' we should accept PUT.
if (!Arrays.asList("put", "post").contains(method)) {
return false;
}
String contentType = request.getContentType();
return (contentType != null &&contentType.toLowerCase().startsWith("multipart/"));
}
};
}
No comments:
Post a Comment