在IE11中下载文件获取错误“'Uint8Array'未定义” [英] Download file in IE11 get error "'Uint8Array' is undefined"

查看:2489
本文介绍了在IE11中下载文件获取错误“'Uint8Array'未定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在JS代码中是 -

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

这给我发错误


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

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

错误是 - 'Uint8Array'未定义,我的IE版本是 - IE11

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

推荐答案

我的角度版本是1.2.26,更高版本的角度1.5
支持Uint8Array并添加

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" />


这篇关于在IE11中下载文件获取错误“'Uint8Array'未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆