I want to display a docx
-file on my browser. But I am having problem with the media type for docx
-file.
This is my sample code:
@RequestMapping("/view")
public @ResponseBody HttpEntity<byte[]> view(@RequestParam(value = "fileId") int id) throws IOException {
FileDaoImplement fdi = new FileDaoImplement();
Files f = fdi.getFile(id);
byte[] document = f.getByte();
HttpHeaders header = new HttpHeaders();
header.setContentType("What should I use to show a docx file??");
header.set("Content-Disposition", "inline; filename=");
header.setContentLength(document.length);
return new HttpEntity<byte[]>(document, header);
}
you could try with specifying the Mediatype
your request produces.
@RequestMapping(path = "/view", produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
not sure if you can get it to work with a byte[]
, but you could use Resource
as return-type instead like:
@GetMapping(path = "/word", produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
public @ResponseBody HttpEntity<Resource> words() throws IOException {
return new HttpEntity<Resource>(new ClassPathResource("/static/hello word.docx"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With