Skip to content

File downloaded on windows have no extension #1

@pdavid0

Description

@pdavid0

Not tested on UNIX, but on Windows 8.1 /download returns a file named 'download'.

By adding correct headers I download a more comprehensible file : 'd411b07f-ef8c-437d-910e-b4b48db8e878.mp4'

  download: function (req, res) {
    var path = '.tmp\\uploads\\'+req.param('path');
    console.log(path);
    var mime = require('mime');
    var mimetype = mime.lookup(path);

    res.setHeader('Content-disposition', 'attachment; filename=' + path);
    res.setHeader('Content-type', mimetype);

    require('fs').createReadStream(path)
    .on('error', function (err) {
      return res.serverError(err);
    })
    .pipe(res);
  }
};

Edit : removing "Content-disposition" streams the file to the browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions