0

i am trying to upload a image in mongoose collection using nodejs & express, first i tried in uploading in temporary folder it's works perfectly. but inserting in to mongoose collection using GridFS query is difficult to me, i familiar to creating schema and insert query. please guide me. here i giving my server side code for how i uploading file to temporary folder.

exports.uploadimg = function(req, res){
    console.log("c1",req.files);
    console.log("c2",req.files.uploaded_file.originalFilename);
    console.log("c3",req.files.uploaded_file.path);
    fs.readFile(req.files.uploaded_file.path, function (err, data){
        var dirname = "/home/Mel/www/2013/img-folder";
        var newPath = dirname + "/classes/" +   req.files.uploaded_file.originalFilename;
        fs.writeFile(newPath, data, function (err) {
            if(err){
                res.json({'response':"Error"});
            }else {
                res.json({'response':"Saved"});
            }
        });
    });        
Alessio
  • 3,404
  • 19
  • 35
  • 48
MATH.h
  • 11
  • 11

1 Answers1

0

Please checkout following link to find out solution of this question

Storing data stream from POST request in GridFS, express, mongoDB, node.js

Thanks

Community
  • 1
  • 1
Dineshaws
  • 2,065
  • 16
  • 26