I am using nodejs mongodb mongoose and gridfs. when I try to get the file from it, filname everthing works fine, if I want to get it by the id that I get Error: the file you want to read does not exist. I have the following console.log code ("res.pic_id:" + res.pic_id), I get the correct ObjectId. Here is the code:
var GridFS = require('GridFS').GridFS; var myFS = new GridFS('db'); var fs = require('fs') var Profile = db.model('Profile'); Profile.findOne({'_id' : clientID},['_id', 'username','pic_id','pic_filename'],function(err, res){ if (err) { console.log("ERROR serching user info: " + err); callback(JSON.stringify(JSONRes(false, err))); } else { if (res) { console.log("res.pic_id : " + res.pic_id); myFS.get(res.pic_id,function(err,data){ if (err) console.log("ERROR "+err) else { callback(data); }}) }; } else { callback(JSON.stringify(JSONRes(false, err))); } } })
Thanks!
Liatz source share