【问题标题】:Large files download issue on Google ChromeGoogle Chrome 上的大文件下载问题
【发布时间】:2016-11-30 15:20:32
【问题描述】:

这个问题快把我逼疯了。

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

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

我正在使用 jQuery 调用 API,使用 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);

    });

【问题讨论】:

    标签: javascript jquery google-chrome asp.net-web-api


    【解决方案1】:

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

    http://danml.com/download.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 2016-02-18
      • 2012-03-14
      • 2022-01-11
      • 2014-02-15
      • 1970-01-01
      • 2021-10-20
      相关资源
      最近更新 更多