Forum Discussion

fredi_fuchs84's avatar
fredi_fuchs84
New Member
6 years ago

How to return a Docx File?

Hello,

 

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");
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);


return ResponseEntity.ok()
// Content-Disposition
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename)
// Content-Type
.contentType(MediaType.APPLICATION_OCTET_STREAM)
// Contet-Length
.contentLength(pdfContents.length) //
.eTag(objectId)
.body(byteArray);

 

Thanks in advanced

 

No RepliesBe the first to reply