aheckmann / gridfs-stream

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

Cannot read property 'w' of undefined #53

Closed bigmeech closed 10 years ago

bigmeech commented 10 years ago

I'm instatiating the grid like this.

var fs = require("fs");
var gridStream = require("gridfs-stream");
var mongoose = require("./database");
var grid = gridStream(mongoose.connection, mongoose.mongo);

exports.getGrid = function(){
    return grid;
}

here is how i'm using the gridStream

var gridStore =  require("../lib/gridStore");
var fs = require("fs");

var grid = gridStore.getGrid();
var file = req.files.productPic;
var gridStream = grid.createWriteStream({
        filename:file.name,
        mode:"w",
        root:"productImages",
        metadata:file
});
fs.createReadStream(file.path).pipe(gridStream);
fs.on("end",function(){
        res.send("Uploaded");
 });
fs.on("error", function(err){
        res.json({error:true,message:"Error uploading file",details:err});
})

what am i doing wrong?