This is a brief version of this article. It is not easy to find the right keyword for Google unless you know how.
The key is to set both content-type and Content-Disposition header. Here’s the code from the web page above:
// Set the headers.
res.setContentType("application/x-download");
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
res.setContentType("application/x-download");
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
By setting content-type to x-download, most browsers won’t guess what to do via file extension. And then we set Content-Disposition to attachment and supply the filename so the download dialog will show up and use the file name we supplied.
This is especially helpful if you want your user to save some jpg/gif files on your web page.
Tags: misc, web development
Post a Comment
You could use <code type="name"> to get your code colorized