IE 11无法从Angular 2中的字节数组创建文件对象 [英] IE 11 failed to create file object from byte array in Angular 2

查看:143
本文介绍了IE 11无法从Angular 2中的字节数组创建文件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我IE11为什么在最后一行抛出错误-

Can anybody tell me why IE11 is throwing error at the last line -

this.document = this.control.value;
  const bytes = 
this.documentService.base64toBytes(this.document.documentBlob.documentData, 
       this.document.documentDataFormat);
const file = new File(bytes, this.document.documentName, { type: 
       this.document.documentDataFormat });

这在Chrome和Firefox中都可以使用.IE抛出对象错误-

This is working in both Chrome and Firefox.IE throws object error -

Object doesn't support this action.

推荐答案

由于IE不支持File API的构造函数,因此我提出了以下解决方法.希望以后对其他人有帮助-

As IE does not support constructor of File API, I have come up with the following workaround. Hope this helps to others in future -

const bytes = this.documentService.base64toBytes(this.document.documentBlob.documentData, this.document.documentDataFormat);
let file: File;
try {
  file = new File(bytes, this.document.documentName, { type: this.document.documentDataFormat });

  if (this.uploader.isFile(file)) {
    this.uploader.addToQueue([file]);
  }
} catch (err) { // Workaround for IE 11
  const blob = this.documentService.base64ToBlob(this.document.documentBlob.documentData,
    this.document.documentDataFormat);
  file = this.documentService.blobToFile(blob, this.document.documentName);
  this.uploader.addToQueue([file]);

这篇关于IE 11无法从Angular 2中的字节数组创建文件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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