@RequestMapping("download")
public ResponseEntity<byte[]> download(Long fileKey) throws IOException {
HttpHeaders headers = new HttpHeaders();
String fileName=new String(massMessage.getFileName().getBytes("UTF-8"),"iso-8859-1");
headers.setContentDispositionFormData("attachment", fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
byte[] data = new byte[2];//要下載的數據流
return new ResponseEntity<byte[]>(data, headers, HttpStatus.CREATED);
}
下載時提示:
下載時提示ie無法打開該站點,請求的站點不可用或找不到
類似信息
修改為下面的就OK了,主要是HttpStatus.CREATED修改為HttpStatus.OK
原因是IE 不支持201的狀態碼,修改為200就行了
@RequestMapping("download")
public ResponseEntity<byte[]> download(Long fileKey) throws IOException {
HttpHeaders headers = new HttpHeaders();
String fileName=new String(massMessage.getFileName().getBytes("UTF-8"),"iso-8859-1");
headers.setContentDispositionFormData("attachment", fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
byte[] data = new byte[2];//要下載的數據流
return new ResponseEntity<byte[]>(data, headers, HttpStatus.OK);
}
