本文介绍了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.

推荐答案

无需使用 FileReader API .直接流化 file 对象更有效.

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 对象,因为它们只是 Blob .这样可以避免将所有文件都放入内存的开销.

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 十分重要,这样 XHR发送方法可以设置内容类型标头.否则,AngularJS框架将使用内容类型 application/json 覆盖.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 21:28