Download file in IE11 get error "Uint8Array" - undefined "

I am creating an application in which I upload a file. To do this, I get a response from the java class in js and load this answer. For this, my java code is

@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();
}

And in the JS code there is -

     $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);
                   });
}

It gives me an error in

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

The error is "'Uint8Array' undefined" and my version of IE is IE11

+6
source share
2 answers

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

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

Blob , responseType: "blob".

0

All Articles