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

Content-Disposition filename issue. #14

@xieyang784

Description

@xieyang784

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions