ResponseEntity 文件下载,电脑下载可以正常打开,手机下载无法打开或打开乱码,这种情况是因为什么?-灵析社区

我爱了你呢

下载文件功能,电脑下载可以正常打开,手机下载无法打开,或者打开乱码 后台代码 HttpStatus statusCode = HttpStatus.OK; HttpHeaders headers = new HttpHeaders(); if (download) { String fileName = new String(r.getName().getBytes(), "ISO8859-1"); headers.add("Content-Disposition", "attachment;filename=" + fileName); } Resource resource = resourceLoader.getResource("file:" + path + "/" + id); InputStream in = resource.getInputStream(); byte[] body = new byte[in.available()]; in.read(body); ResponseEntity streamResponse = new ResponseEntity(body, headers, statusCode); return streamResponse; 前端下载 function handleDownload(file: any) { console.log(file) let a = document.createElement('a') let event = new MouseEvent('click') a.download = file.name a.href = file.url a.dispatchEvent(event) }

阅读量:14

点赞量:0

问AI
乘03060920
"handleDownload(file: any)" file.url 是什么东西?移动端对于 bloburl 和 dataurl 支持都不太行