I want to return the generated PDF file through the spring -mvc-rest controller. This is a shortened version of the code I'm currently using:
@RestController
@RequestMapping("/x")
public class XController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ResponseEntity<byte[]> find() throws IOException {
byte[] pdf = createPdf();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "pdf"));
headers.setContentDispositionFormData("attachment", "x.pdf");
headers.setContentLength(pdf.length);
return new ResponseEntity<byte[]>(pdf, headers, HttpStatus.OK);
}
}
This works almost fine, it just returns the actual base64 encoded byte array :(
curl -i 'http://127.0.0.1:8080/app/x'
Server: Apache-Coyote/1.1
Content-Disposition: form-data; name="attachment"; filename=x.pdf"
Content-Type: application/pdf
Content-Length: 138654
Date: Fri, 08 Jan 2016 11:25:38 GMT
"JVBERi0xLjYNJeLjz9MNCjMyNCAwIG9iag [...]
(By the way, the answer doesnβt even contain a closure ":)
Any hints appreciated!
source
share