Send files in Koa

Koa.js framework provides the response.attachment method to prompt file for download on the client. This method creates an attachment Content-Disposition header to make this possible.


A simple application that sends package.json:

We should set status or body to create minimum data for the response.

The second argument of .attachment method its an object. It supports the next values:

  • fallback – string or boolean
  • type – string

If you liked this, please help spread the word by hitting the recommend button below. Thanks!