export function fileDownLoad(name) {
return axios.get(baseUrl + '/fileDownLoad/' + name, {
responseType: 'blob'
}).then(res => {
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(res)
downloadElement.href = href
downloadElement.download = name
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}).catch(error => console.log(error))
}
@ApiModelProperty("转出申请下载")
@GetMapping("/fileDownLoad/{fileName}")
public void fileDownLoad(HttpServletResponse response,@PathVariable String fileName) throws Exception {
String filePath = PbhConfig.getProfile() + "/" + fileName;
InputStream in = new FileInputStream(filePath);
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
OutputStream out = response.getOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
in.close();
out.close();
}