influxweb
3/30/2017 - 2:49 AM

How to force a file download in the browser? — First published in fullweb.io issue #92

How to force a file download in the browser? — First published in fullweb.io issue #92

How to force a file download in the browser?

The use case is simple, you have /reports/593874951.pdf on your web server and want to let your user download it — and if possible with a meaningful name.

In the past, you may tried using the Content-Disposition HTTP header to achieve this, but today, with Safari getting the support for the download attribute it’s going to simplify a lot of things.

Using the download attribute is simple as pie:

<a href="/reports/593874951.pdf" download="report.pdf">
   Download report
</a>

The browser will then prevent the file to be opened in the browser and force its download, with the name specified in download’s value.