FileReader readAsDataURL()方法无法读取打字稿中的大pdf文件24 MB [英] FileReader readAsDataURL() method not read large pdf file 24 MB in typescript

查看:97
本文介绍了FileReader readAsDataURL()方法无法读取打字稿中的大pdf文件24 MB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

let fileReader = new FileReader();
 fileReader.readAsDataURL(file);

readAsDataURL方法可以读取较小的文件(小于5mb)并上传也可以.但是,当我上传较大的文件(24MB)时无法读取它们,filereader.result在IE浏览器中为空.在Chrome中,它可以正常工作./p>

readAsDataURL method reading smaller files( below 5mb) file and upload also working fine.But when I upload larger file( 24MB) it is not reading them, filereader.result getting null in IE browser.In Chrome it's working fine.

推荐答案

无需使用

There is no need to use the FileReader API. It is more efficient to stream the file object directly.

var config = { headers: { 'Content-Type': undefined } };

$http.post(url, file, config)
  .then(function (response) {
    var data = response.data;
    var status = response.status;
    var statusText = response.statusText;
    var headers = response.headers;
    var config = response.config;

    console.log("Success");
    return response; 
}).catch(function (errorResponse)
    console.log("Error");
    throw errorResponse;
});

XHR发送方法知道如何流 file 对象,因为它们只是

The XHR Send Method knows how to stream file objects as they are just a special type of Blob. This avoids the overhead of bringing all of the file into memory.

将内容类型标头设置为 undefined 十分重要,这样

It as important to set the content type header to undefined so that the XHR send method can set the content type header. Otherwise the AngularJS framework will override with content type application/json.

有关更多信息,请参见 AngularJS $ http服务API参考.

For more information, see AngularJS $http Service API Reference.

这篇关于FileReader readAsDataURL()方法无法读取打字稿中的大pdf文件24 MB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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