PDF download using Angular saveAs with .net core API failing in chrome

0 Answers 822 Views
PDF Export
Vijay
Top achievements
Rank 1
Vijay asked on 18 Sep 2022, 06:21 PM

Hi,

In my organization's project we are using telerik controls and for one requirement we were calling saveAS method of angular by passing proxy URL and getting PDF content from .net API. It was displaying PDF in new tab and working fine with all browser.

We followed below approach.

https://www.telerik.com/kendo-angular-ui/components/file-saver/server-proxy/

Now , we are upgrading our apps for latest angular and .net core 6 version . During upgrade we noticed that we have to change the .net API method something like below as HttpResponseMessage is not working in .net 6.

Following changes we made for API method.

[HttpPost]
        [Route("savepdfdocument")]
        public FileContentResult SavePDF([FromForm]FileData file)
        {


            var data = Convert.FromBase64String(file.Base64);
            Response.Headers.Add("Content-Disposition", "inline; ; filename=" + file.FileName);
            Response.Headers.Add("Transfer-Encoding", "identity");
            return File(data, file.ContentType); //file.ContentType ="application/pdf"

}

Now if we are using "Content-Disposition" as "attachement " with file name then all browser download the PDF file correctly.

Issue: With Response.Headers.Add("Content-Disposition", "inline; ; filename=" + file.FileName);

All browser display the PDF correctly in new tab, no issue in display.

But once we try to download the PDF file from browser PDF viewer then following issue occurred in chrome and IE edge(in FF it is working).

1- In download file name it taking as action method name without .pdf, in our case 'savepdfdocument'

2- Download fails with message Network Error(while not network call happening)

We checked headers , and it have all necessary value like below

  1. Content-Disposition:
    inline; filename=34455.pdf
  2. Content-Length:
    73847
  3. Content-Type:
    application/pdf

Please suggest/help if we are doing anything wrong here?


Yanmario
Telerik team
commented on 21 Sep 2022, 12:40 PM

Hi Vijay,

Thank you for the provided details.

I am not entirely sure why the network error is present in chromium-based browsers and some further research might be required by the developers as the issue seems to be related to chromium-based browsers and how they download the pdf files. Mozilla on the other hand runs on a different engine and it makes sense that some issues might not be related.

We do try to provide help and guidance with issues outside Kendo UI for Angular library, but in this case, it is hard to determine from the provided information or to provide a suggestion based on that.

I would recommend doing some research on the error at hand and maybe check if chromium has a logged issue on this matter:

https://bugs.chromium.org/p/chromium/issues/list?q=component%3AInternals%3EPlugins%3EPDF&can=2

Regards,
Yanmario
Progress Telerik

No answers yet. Maybe you can help?

Tags
PDF Export
Asked by
Vijay
Top achievements
Rank 1
Share this question
or