parita porwal parita porwal - 5 months ago 45
Javascript Question

Download file in IE11 get error "'Uint8Array' is undefined"

I am creating a application in which I am downloading a file. For this I get response from java class in js and download this response.For this my java code is -

@ApiOperation(value = "",
notes = "")
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";;
}else {
mimeType = URLConnection.guessContentTypeFromName(file.getName());
if (mimeType == null) {"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) {
return Response
.ok(inputStream, mimeType)
.header("Content-Disposition", "attachment; filename=\""+file.getName()+"\"")
.header("Content-Length", file.length())

And in JS code is -

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

This give me error at

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

Error is - "'Uint8Array' is undefined" and my IE version is - IE11

Answer Source

My angular version is 1.2.26 and Uint8Array is supported in later version of angular 1.5

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download