Force the browser to download a link


If you are serving the file from code, add the Content-Disposition header:

	response.setHeader("Content-Disposition", "attachment;filename=myFile.txt");

If you are serving the file from the filesystem, add the download attribute to the a element:

	<a download="myFile.txt" href=...

If you are serving the file from memory, use a data: url:

	<a download="myFile.txt" href="data:application/octet-stream;base64,...

Date: 2013-02-17

Tags:  web

Share: