gpt4 book ai didi

javascript - 在 IE11 中下载文件出现错误 "' Uint8Array' is undefined”

转载 作者:数据小太阳 更新时间:2023-10-29 05:24:45 31 4
gpt4 key购买 nike

我正在创建一个正在下载文件的应用程序。为此,我从 js 中的 java 类获得响应并下载此响应。为此,我的 java 代码是 -

@ApiOperation(value = "",
notes = "")
@Path("/getProjectJSONTODRAW/{implementation}")
@GET
@Timed
public Response getProjectJSONTODRAW(@PathParam("implementation") String implementation) {
File file = new File(path+File.separator+fileName);
InputStream inputStream =null;
String mimeType =null;
if (!file.exists()) {
String errorMessage = "Sorry. The file you are looking for does not exist";
log.info(errorMessage);
}else {
mimeType = URLConnection.guessContentTypeFromName(file.getName());
if (mimeType == null) {
log.info("mimetype is not detectable, will take default for the file "+file.getName());
mimeType = "application/octet-stream";
}
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return Response
.ok(inputStream, mimeType)
.header("Content-Disposition", "attachment; filename=\""+file.getName()+"\"")
.header("Content-Length", file.length())
.build();
}

而在 JS 代码中是 -

     $http.get('/api/1/explore/getProjectJSONTODRAW/implementation', {
responseType: 'arraybuffer'
})
.success(function(response) {
var a = document.createElement("a");
document.body.appendChild(a);
var fileName = "abc.pdf";
var mimeType = "application/pdf";
var blob = new Blob([response], {
type: mimeType
}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
var isIE = false || !!document.documentMode;
if (isIE) {
a.style.cssText = "display: none;"
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
a.style = "display: none";
a.click();
window.URL.revokeObjectURL(url);
}
}).catch(function(error) {
console.log(error);
});
}

这给我错误

var blob = new Blob([response], {type: mimeType})

错误是 - “'Uint8Array' is undefined” 我的 IE 版本是 - IE11

最佳答案

我的angular版本是1.2.26,angular 1.5以后的版本支持Uint8Array并添加

<meta http-equiv="X-UA-Compatible" content="IE=11" />

关于javascript - 在 IE11 中下载文件出现错误 "' Uint8Array' is undefined”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46316539/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com