res.attachment()

Sets the “Content-Disposition” header of the current response to “attachment”. If a filename is given, then the “Content-Type” will be automatically set based on the extension of the file (e.g. .jpg or .html), and the “Content-Disposition” header will be set to “filename=filename“.

Usage

  1. res.attachment([filename]);

Example

  1. res.attachment();
  2. // -> response header will contain:
  3. // Content-Disposition: attachment
  4. res.attachment('path/to/logo.png');
  5. // -> response header will contain:
  6. // Content-Disposition: attachment; filename="logo.png"
  7. // Content-Type: image/png