Home > front end >  Content-disposition inline filename not working
Content-disposition inline filename not working

Time:04-20

There are some old questions regarding this topic, but the issue I'm facing is just some days old so thought to create a new thread.

I am using the content-disposition inline combined with filename to open a PDF file directly in Browser.

content-disposition: inline; filename="MyFile.pdf"

Until a couple of days ago it was working fine in Chrome and Firefox, (I know that in old IE versions the filename parameter wouldn't work in inline), PDF was opening in browser with the correct (provided) filename. Now it seems like the filename parameter isn't working anymore even for Chrome and Firefox. The PDF is opened correctly but created with a name from the last part of the URL, which in my case is just pdf (https://.../pdf).

If I switch to attachment instead of inline the filename works fine, file gets downloaded with the correct filename. Issue is that I need to open the file in browser and not download it.

Is inline with filename not anymore possible in Chrome and Firefox?

CodePudding user response:

I have found that in my environment, URLs containing basic authentication do not allow inline display of pdfs.

CodePudding user response:

I am facing very similar problem lately.

Strangely, when making a POST request for PDF document, the filename is ignored. But if I make a GET request, everything works like before. PDF is shown correctly and SaveAs also works with correct filename.

I ended up making a redirect on the server side, so the last request is a GET.

Another thing I noticed is, when the user clicks on the Download (Save As) button in the browser's PDF viewer, the server gets another request for the document and serves the content again. The Print command however does not make another request and prints the content already in the PDF viewer.

Hope this info helps, even if only to let you know, you're not the only one with this problem.

  • Related