aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

Error: ENOENT, open 'null/60c0f337f3413edbc5eb3bb27fa3269f' #49

Closed gayatrisreevalsan closed 10 years ago

gayatrisreevalsan commented 10 years ago

var conn = mongoose.createConnection(config.db); conn.once('open', function (err) { if (err) { next(err); return; } var source = fs.createReadStream(req.files.sample.path);

            var gfs = Grid(conn.db, mongoose.mongo);
            var id = mongoose.Types.ObjectId();
            var target = gfs.createWriteStream({
                _id: id,
                filename: req.files.sample.name
            });

            source.pipe(target).on('close', function () {
                project.documentation = id;
                persistProject(req, res, next, project);
            });

When I'm trying to upload it os showing the below error. Terminating application: undefined

events.js:72 throw er; // Unhandled 'error' event ^ Error: ENOENT, open 'null/60c0f337f3413edbc5eb3bb27fa3269f'

Why this error is coming? Please help me to solve it.

mshafieluru commented 10 years ago

The Source should include filename as well. so it should be

source(fullfilepath).pipe(target).