Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Content-Disposition filename issue. #14

Open
xieyang784 opened this issue Dec 4, 2017 · 1 comment
Open

Content-Disposition filename issue. #14

xieyang784 opened this issue Dec 4, 2017 · 1 comment

Comments

@xieyang784
Copy link

In lib/index.js round 232 lines:

MongoStorage.prototype.__download = function(file, res, callback) {
    var gfs, read;
    if (callback == null) {
      callback = (function() {});
    }
    gfs = Grid(this.db, mongodb);
    read = gfs.createReadStream({
      _id: file._id
    });
    res.set('Content-Disposition', "attachment; filename=\"" + file.filename + "\"");
    res.set('Content-Type', file.metadata.mimetype);
    res.set('Content-Length', file.length);
    return read.pipe(res);
  };

If file.filename contains Chinese code or other un-standard code express will throw error:

TypeError: The header content contains invalid characters
    at validateHeader (_http_outgoing.js:492:11)
    at ServerResponse.setHeader (_http_outgoing.js:496:3)  

So change:
res.set('Content-Disposition', "attachment; filename=\"" + file.filename + "\"");
to:
res.attachment(file.filename);
will correct this issue.

@xieyang784
Copy link
Author

@jdrouet please help review it, thanks.

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

No branches or pull requests

1 participant