|
1 | 1 | package com.baeldung.spring.web.config; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
3 | 6 | import org.springframework.context.annotation.Bean; |
4 | 7 | import org.springframework.context.annotation.ComponentScan; |
5 | 8 | import org.springframework.context.annotation.Configuration; |
6 | 9 | import org.springframework.core.io.ClassPathResource; |
| 10 | +import org.springframework.http.MediaType; |
| 11 | +import org.springframework.http.converter.ByteArrayHttpMessageConverter; |
| 12 | +import org.springframework.http.converter.HttpMessageConverter; |
7 | 13 | import org.springframework.web.multipart.commons.CommonsMultipartResolver; |
8 | 14 | import org.springframework.web.servlet.ViewResolver; |
9 | 15 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
@@ -69,4 +75,25 @@ public ViewResolver resourceBundleViewResolver() { |
69 | 75 | return bean; |
70 | 76 | } |
71 | 77 |
|
| 78 | + @Override |
| 79 | + public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) { |
| 80 | + converters.add(byteArrayHttpMessageConverter()); |
| 81 | + } |
| 82 | + |
| 83 | + @Bean |
| 84 | + public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() { |
| 85 | + final ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter(); |
| 86 | + arrayHttpMessageConverter.setSupportedMediaTypes(getSupportedMediaTypes()); |
| 87 | + |
| 88 | + return arrayHttpMessageConverter; |
| 89 | + } |
| 90 | + |
| 91 | + private List<MediaType> getSupportedMediaTypes() { |
| 92 | + final List<MediaType> list = new ArrayList<MediaType>(); |
| 93 | + list.add(MediaType.IMAGE_JPEG); |
| 94 | + list.add(MediaType.IMAGE_PNG); |
| 95 | + list.add(MediaType.APPLICATION_OCTET_STREAM); |
| 96 | + |
| 97 | + return list; |
| 98 | + } |
72 | 99 | } |
0 commit comments