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

feat(index): add getFileReadStreamById method #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,20 @@ MongoStorage = (function() {
}, callback);
};

MongoStorage.prototype.getFileReadStreamById = function(id) {
var gfs;
gfs = Grid(this.db, mongodb);
return gfs.createReadStream({
_id: id
});
};

MongoStorage.prototype.__download = function(file, res, callback) {
var gfs, read;
var read;
if (callback == null) {
callback = (function() {});
}
gfs = Grid(this.db, mongodb);
read = gfs.createReadStream({
_id: file._id
});
read = this.getFileReadStreamById(file._id);
res.set('Content-Disposition', "attachment; filename=\"" + file.filename + "\"");
res.set('Content-Type', file.metadata.mimetype);
res.set('Content-Length', file.length);
Expand Down
9 changes: 6 additions & 3 deletions source/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ class MongoStorage
getFileById: (id, callback) ->
@__getFile _id: id, callback

__download: (file, res, callback = (-> return)) ->
getFileReadStreamById: (id) ->
gfs = Grid @db, mongodb
read = gfs.createReadStream
_id: file._id
gfs.createReadStream
_id: id

__download: (file, res, callback = (-> return)) ->
read = @getFileReadStreamById file._id
res.set 'Content-Disposition', "attachment; filename=\"#{file.filename}\""
res.set 'Content-Type', file.metadata.mimetype
res.set 'Content-Length', file.length
Expand Down