JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 42983843
  • Score
    100M100P100Q310012F
  • License MIT

Create an attachment Content-Disposition header

Package Exports

  • content-disposition

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (content-disposition) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

content-disposition

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Create an attachment Content-Disposition header

Installation

$ npm install content-disposition

API

var contentDisposition = require('content-disposition')

contentDisposition([filename])

Create an attachment Content-Disposition header value using the given file name, if supplied.

res.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf'))

Examples

Send a file for download

var contentDisposition = require('content-disposition')
var destroy = require('destroy')
var http = require('http')
var onFinished = require('on-finished')

var filePath = '/path/to/public/plans.pdf'

http.createServer(function onRequest(req, res) {
  // set headers
  res.setHeader('Content-Type', 'application/pdf')
  res.setHeader('Content-Disposition', contentDisposition(filePath))

  // send file
  var stream = fs.createReadStream(filePath)
  stream.pipe(res)
  onFinished(res, function (err) {
    destroy(stream)
  })
})

Testing

$ npm test

References

License

MIT