我正在使用httpClient方法从服务器下载文件的angular 11上工作。对于小尺寸文件,这很好用。但是对于大文件(大约1GB),尽管我在console.log中获得了链接(例如https://999.99.999.99:99999/DownloadFileServlet?filename=/tmp/ab/1607023356995),但下载仍需要花费大量时间。焦油)在几秒钟后。如果单击此链接,下载将立即开始,但否则将花费大量时间。
这是我的代码:
this.downloads.download(this.downloadInfo.filePathName)
.subscribe(blob => {
saveAs(blob, 'new_file_name');
this.isContentLoading = false;
},
err => {
this.isContentLoading = false;
const message: LogMessage = {severity: Severity.ERROR, message: "Download not finished"};
this.logMessageService.log(message);
}
);
download(fileName: string): Observable<Blob> {
return this.https.get(`https://${this.environment.path}/ab/DownloadFileServlet?
filename=${fileName}`,
{
responseType: "blob",
withCredentials: true,
reportProgress: true
});
}
请分享您的经验,了解如何使用这种方法有效地下载大文件。
因此,如果我不直接使用httpClient,则可以直接提供window.location.href的下载链接,例如:return window.location.href = https://${this.environment.path}/DownloadFileServlet?filename=${fileName}
下载开始更快。尽管我确定这是否是正确的解决方案,但很高兴知道是否有更好的主意。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句