Responsive Ad Area

Share This Post

test

upload zip and rar file using node.js and multer to cloudinary

i’m traying to upload rar and zip file using multer to cloudinary , i upload pdf it works fine, but i want to allow only zip and rar.

here is my code:

    var storage = multer.diskStorage({
  filename: function(req, file, callback) {
    callback(null, curDate + file.originalname);
  }
});

var DocFilter = function (req, file, cb) {
    // accept image files only
    if (!file.originalname.match(/.(pdf||doc|docx)$/i)) {
        return cb(new Error('Only document files are allowed!'), false);
    }
    cb(null, true);
};
var upload = multer({ storage: storage, fileFilter: DocFilter})

i tryed switching to this file.originalname.match(/.(/|zip|rar)$/i
but it did not work

and here is the route:

router.post("/requestsList" , middleware.isLoggedIn ,  upload.single("attach") , function(req , res){
cloudinary.uploader.upload(req.file.path, function(result) {
    var Name = req.body.name ;
    var Gender = req.body.gender ;
    var Email = req.body.email ;
    var PNumber = req.body.phone ;
    var attach = result.secure_url;

var newRequest = {Name: Name , Gender: Gender , Email: Email , PhonenNumber: PNumber , Attachment: attach} ;
Request.create(newRequest , function(err , newlyCreated){
   if(err){
       console.log(err);
       req.flash("error" , err.message);
       res.redirect("back");
   } else{
       console.log(newlyCreated);
       req.flash("success" , "Request Successfully Sent");
       res.redirect("/home") ;
   }
});
});

});


upload zip and rar file using node.js and multer to cloudinary
upload zip and rar file using node.js and multer to cloudinary
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar