2
我已将angular file saver实施到我的项目中,目的是下载文件,它适用于小文件,但对于大于50mb的文件,我会看到下一个错误并在35-50mb之后停止下载。使用角度文件保护程序下载大尺寸文件
net::ERR_INCOMPLETE_CHUNKED_ENCODING
我试图在互联网上调查这个问题,并发现有一个限制下载500MB,因为显然不能在RAM中存储这么多的信息。不幸的是,我没有找到任何其他的解释如何解决这个问题,然后我问了后端的人,我已经得到了答案,他的一切都很好。
那么我的问题在哪里?我该如何解决这个问题?我感谢所有帮助
这里是我的代码部分:
服务
function attachment(obj) {
custom.responseType = "arraybuffer";
delete custom.params.limit;
delete custom.params.offset;
delete custom.params.orderBy;
delete custom.params.insertedAt;
var contentType = obj.mimeType;
var name = obj.displayFilename;
return $http.get(Config.rurl('attachments') + '/' + obj.bucketName + '/' + obj.path + '?displayFilename=' + obj.displayFilename, custom)
.then(function (response) {
var data = new Blob([response.data], { type: contentType });
FileSaver.saveAs(data, name);
delete custom.responseType
})
.catch(function (err) {
delete custom.responseType;
alert("It has happened an error. Downloading has been stopped") ;
});
}
控制器功能
$scope.download = function (obj) {
lovServices.attachment(obj)
}
是的,感谢解决方案和提供的链接。 – antonyboom
由于这是一个AJAX请求,因此在调用saveAs()之前,必须将完整的文件内容加载到浏览器的内存中,对吗?那么这意味着非常大的文件刷新页面将会丢失所有文件内容? – losmescaleros
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)是一个类似于流的异步异步对象。 [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)是一个内存对象。通过将[XHR responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType)设置为Blob,可以避免将其加载到JavaScript内存的步骤。 JavaScript在加载之前将该流传递给FileSaver。 – georgeawg