Forum Discussion

fredi_fuchs84's avatar
New Member
6 years ago

How to return a Docx File?



Im just starting to use swagger and for the moment I like it very much :) but I have a problem which I can't fix by myself.

Perhaps you can help me.


I saw that it is possible to return a PDF file and I was able to do that. My UseCase is that I like to return a docx File but I was not able.


The WebService returns a docx FIle but Word cannot open the file


Here is my Code I hope that you can help me


String filename = "Test.docx";
responseHeaders.setContentDispositionFormData(filename, filename);
responseHeaders.setCacheControl("must-revalidate, post-check=0, pre-check=0");

return ResponseEntity.ok()
// Content-Disposition
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename)
// Content-Type
// Contet-Length
.contentLength(pdfContents.length) //


Thanks in advanced


No RepliesBe the first to reply