Reputation: 1548
Trying to open a PDF in Chrome as suggested in another answer here. However, I'm getting the binary representation instead (see image). Content-disposition=attachment works, but inline doesn't. What am I doing wrong?
Result:
Javaconfig (I think this is enabled by default but adding or removing this code doesn't make a difference):
public class WebConfig extends WebMvcConfigurationSupport {
...
@Bean
public ResourceHttpMessageConverter httpConverter() {
return new ResourceHttpMessageConverter();
}
@Override
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(httpConverter());
super.configureMessageConverters(converters);
}
}
Controller:
@RequestMapping(value="/man", method = RequestMethod.GET)
@ResponseBody
public FileSystemResource manual(HttpServletResponse response) {
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline; filename=manual.pdf");
return new FileSystemResource(servletContext.getRealPath("/resources/manual.pdf"));
}
Upvotes: 0
Views: 144
Reputation: 6724
You need to define produces
.
@RequestMapping(value="/man", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
Upvotes: 1