Skip to content

Commit

Permalink
Added support for file attachment in response.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr committed Jul 19, 2010
1 parent a4324e6 commit b43b9e8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ RequestContext.prototype.renderStatic = function() {
});
};

RequestContext.prototype.sendFile = function(file, fileName) {
var self = this;
fs.stat(file, function(err, stats) {
if(err) {
self.handleError(err);
} else {
if(!fileName) {
fileName = file.substring(file.lastIndexOf('/') + 1);
}
var extn = fileName.substring(fileName.lastIndexOf('.') + 1);
self.headers['content-type'] = mime.mimes[extn]
? mime.mimes[extn]
: 'application/octet-stream';

self.headers['content-disposition'] = 'attachment; filename=' + fileName;
sendStatic(file, stats, self);
}
});
};

RequestContext.prototype.renderError = function(status, error) {
this.status = status;
if(error === undefined) {
Expand Down

0 comments on commit b43b9e8

Please sign in to comment.