@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = {"/download/excel-report"},
method = RequestMethod.GET)
public HttpEntity<byte[]> downloadExcelReport() {
/** assume that below line gives you file content in byte array **/
byte[] excelContent = getReportContent();
// prepare response
HttpHeaders header = new HttpHeaders();
header.setContentType(new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
header.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=my_file.xls");
header.setContentLength(excelContent.length);
return new HttpEntity<byte[]>(excelContent, header);
}
|