使用 angular 文件保护程序下载大文件

Download large size files with angular file saver

我已将 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)
    }

而不是下载到内存并转换为 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;
    });

这避免了再次将流转换为 arraybuffer and then making a blob 的内存开销。

有关详细信息,请参阅 MDN XHR API ResponseType