Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File downloaded on windows have no extension #1

Open
pdavid0 opened this issue Nov 27, 2014 · 0 comments
Open

File downloaded on windows have no extension #1

pdavid0 opened this issue Nov 27, 2014 · 0 comments

Comments

@pdavid0
Copy link

pdavid0 commented Nov 27, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant