Friday 5 May 2017

Upload PDF file using node js

I am trying to upload PDF file using node js but I am able to do that. Please help if there is any plugin or multer can be used for the same. Here I am uploading profile image for same I want to upload PDF file and it can store more than 30 files.

//var multer  = require('multer')
//var upload = multer({ dest: 'public/uploads/' });

router.post('/speaker', upload.single('profile_pic'), function (req, res) {
  
    var speakerForm = JSON.parse(req.body.speaker);
    var speaker = new Speaker();
    speaker.name = speakerForm.name;
    speaker.job_title = speakerForm.job_title;
    speaker.email = speakerForm.email;
    speaker.company = speakerForm.company;
    speaker.description = speakerForm.description;
    speaker.uid = speakerForm.uid;
    if(req.file){
        var profile_pic = req.file;
            profile_pic.destination = "uploads/";
            profile_pic.path = "uploads/"+profile_pic.filename;
            speaker.profile_pic = profile_pic;
    }
 
    speaker.save(function(err,speakerobj){
        if(err){
          return res.send(500, err);
        }
        return res.json(speakerobj);
    });

});


via Ikshit Mathur

No comments:

Post a Comment