如何在javascript中将内存流数据转换为blob?

问题描述

在服务器端,我使用 FastReport 创建一个 Pdf 并将其转换为内存流。现在,在客户端为了下载 pdf,我需要将该流转换为 blob。

但是如何将内存流转换为 blob?

JS

$.ajax({
      url: '/Controller/GetPdf',type: 'POST',success: function (data) 
      { 
           var blob = data.toBlob(); // need to kNow what to do here.

           const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.style.display = 'none';
            a.href = url;
            a.download = 'abc.pdf';
            document.body.appendChild(a);
            a.click();
     }

C#

public FileResult GetPdf()
{
      var webReport = new FastReport.Web.WebReport();
      var ms = new MemoryStream();
      webReport.Report.Prepare();

      webReport.Report.Export(new PDFExport(),ms);
      ms.Position = 0;
      return File(ms,"application/pdf","fileName.pdf");
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)