Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = "")
@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 JS code 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);
                   });
}

This give me error at

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

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

like image 920
parita porwal Avatar asked Sep 20 '17 08:09

parita porwal


People also ask

What is INET_E_download_failiure error in Internet Explorer 11 and Microsoft Edge?

Some Internet Explorer 11 and Microsoft Edge users are reporting that they end up seeing the INET_E_DOWNLOAD_FAILIURE error whenever they try to visit a webpage. In most cases, affected users are saying that this problem happens with every URL, including big domains like google.com, amazon.com, etc.

Why can't I download files in Internet Explorer 11?

Your Internet Explorer Security may have been modified to disallow downloads. You simply need to revert the changes you made to the settings. Enable file download in Internet Explorer 11. a. Close any Internet Explorer or Windows Explorer windows that are currently open.

Why is my Internet Explorer 11 not working on Windows 10?

Corrupted IE cache – If you’re using Internet Explorer 11, you might be dealing with this browser’s notorious inability to clean it’s cache properly. Whenever the IE 11 cache ends up causing web server accessibility issues, you should try resetting Internet Explorer to a clean state and see if this ends up fixing the issue.


1 Answers

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

<meta http-equiv="X-UA-Compatible" content="IE=11" />
like image 142
parita porwal Avatar answered Oct 31 '22 00:10

parita porwal