ant*_*oom 3 javascript html5 blob angularjs filesaver.js
我已经在我的项目中实现了角度文件保护程序,目的是下载文件,它对于小文件也可以正常工作,但是对于大于50mb的文件,我看到下一个错误,并且在35-50mb之后停止下载。
net::ERR_INCOMPLETE_CHUNKED_ENCODING
Run Code Online (Sandbox Code Playgroud)
我试图调查互联网上的这个问题,发现下载限制为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") ;
});
}
Run Code Online (Sandbox Code Playgroud)
控制器功能
$scope.download = function (obj) {
lovServices.attachment(obj)
}
Run Code Online (Sandbox Code Playgroud)
而不是下载到内存并转换为Blob。设置responseType为'blob':
//SET responseType to 'blob'
var config = { responseType: ?'?a?r?r?a?y?b?u?f?f?e?r?'? ? 'blob' };
return $http.get(url, config)
.then(function (response) {
?v?a?r? ?d?a?t?a? ?=? ?n?e?w? ?B?l?o?b?(?[?r?e?s?p?o?n?s?e?.?d?a?t?a?]?,? ?{? ?t?y?p?e?:? ?c?o?n?t?e?n?t?T?y?p?e? ?}?)?;?
//USE blob response
var data = response.data;
FileSaver.saveAs(data, name);
})
.catch(function (err) {
alert("It has happened an error. Downloading has been stopped") ;
throw err;
});
Run Code Online (Sandbox Code Playgroud)
这避免了将流转换为arraybuffer然后再次产生blob的内存开销。
有关更多信息,请参见MDN XHR API ResponseType。
| 归档时间: |
|
| 查看次数: |
3664 次 |
| 最近记录: |