Thank you very elliot, i used your second link and i can download file
now, mixing mongodb gridfs and node js fs modules.
But, So far, I can only download .txt files, I have a big problem with
others extensions like .docx, .pdf, ijpg etc..
Here is an example of downloading from my code, thank for your help
var fs = require("fs")
var Mongolian = require("mongolian")
var server = new Mongolian
var db = server.db("test")
var files = db.collection("fs.files")
var mime = require("mime")
var gridfs = db.gridfs()
// Create new file write stream
var stream = gridfs.findOne('test.jpg', function(err, file) {
if (err) throw err
var stream = file.readStream()
var content = ''
stream.on('data',function(chunk) { content +=
chunk.toString() })
stream.on('error', function(error) {
console.log(error)
})
stream.on('end',function() {
// console.log(content)
fs.writeFile('fs/test.jpg', content, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
});
});
In this code i trie to download the file test.jpg from my mongodb
database to my fs folder... the file is created, but it's empty. I
think it's a encoding problem or something.. how to solve it ??? It's
the same with pdf, docx, odt files etc...
Thanks