how to convert memorystream data to blob in javascript?

  ajax, asp.net-mvc, fastreport, javascript, jquery

In the server side, I am creating a Pdf using FastReport and converting it as memorystream. Now, in the Client side in order to download the pdf, I need to convert that stream as a blob.

But how to convert memory stream to 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");
}

Source: Ask Javascript Questions

LEAVE A COMMENT