企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
responseType: 'blob': 不可缺少 ``` function exportLogData(data, file_name) { axios({ method: 'post', url: serverIp + '/sysLog/download', responseType: 'blob', data, headers: { 'Access-Control-Allow-origin': '*', 'Content-Type': 'application/json; charset=UTF-8', 'Token':JSON.stringify(getToken())} }).then((res) => { if (res && res.status === 200) { const blob = new Blob([res.data]) let brower = ''; if (navigator.userAgent.indexOf('Edge') > -1){ brower = 'Edge' } if ('download' in document.createElement('a')){ if (brower === 'Edge') { navigator.msSaveBlob(blob, file_name); return } let url = window.URL.createObjectURL(res.data); let link = document.createElement('a'); link.style.display = 'none'; link.href = url; link.setAttribute('download', file_name); if(!document.getElementById(file_name)) { document.body.appendChild(link); } link.click(); URL.revokeObjectURL(link.herf); document.body.removeChild(link) } else { //IE10+下载 navigator.msSaveBlob(blob, file_name) } } }).catch(error => { console.log(error) }) } ``` 后端 ~~~ @GetMapping("/download-report/{id}") @ApiOperation("下载报告:/opsTestPlan/download-report/{id}") public ResponseData downloadReport(HttpServletResponse response, @PathVariable Long id) { ObsObject obsObject = testPlanService.downloadReport(id); try(InputStream input = obsObject.getObjectContent(); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());){ response.setContentType("application/octet-stream"); int len; byte[] b = new byte[1024]; while ((len=input.read(b)) != -1){ outputStream.write(b, 0, len); } outputStream.flush(); }catch (Exception ex) { throw new ServiceException(ex.getCause()); } return null; } ~~~