谷歌浏览器上的大文件下载问题

问题描述:

这个问题让我疯狂。谷歌浏览器上的大文件下载问题

我想导出由iTextSharp生成的pdf报告。

我有一个ASP.NET Web API项目,我有我的代码生成PDF文件。

我打电话给API使用jQuery使用post方法发送一些参数,获取基于这些过滤器的查询结果并导出它们。

在IE和FireFox上都可以正常工作。涉及到大于5MB的文件时,该问题与Google Chrome有关。该过程完成,但我从Chrome获得“下载失败 - 网络错误”。

这个问题似乎与javascript部分有关,因为字节数组正确返回。

对此有任何帮助吗?

我的ASP.NET Web API方法代码:

[HttpPost] 
public byte[] ExportPDFRequestsList(RequestFilter filter) 
{ 
    //Method contains the logic of export that has no issues 
    return RequestsService.ExportPDFRequestsList(filter); 
} 

我的JavaScript代码来下载文件:

$.when(
     //jQuery ajax post method -- works fine 
     AppObj.JsonCall("Post", exportPDFRequestsListUrl, true, parameter) 

    ).then(function (response) { 
     var newdata = "data:application/pdf;base64," + escape(response); 
     var a = document.createElement("a"); 
     //build download link: 
     a.href = newdata; 
     a.setAttribute("download", "Requests.pdf"); 
     document.body.appendChild(a); 
     setTimeout(function() { 

      var e = document.createEvent("MouseEvents"); 

      e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null 
     ); 
      a.dispatchEvent(e); 
      document.body.removeChild(a); 

     }, 999); 

    }); 

,我发现这个库,解决了我的问题:

http://danml.com/download.html