Home > database >  Multer Didn't work for me not storing image in local Folder or Database
Multer Didn't work for me not storing image in local Folder or Database

Time:09-28

Now what can i do to store files in db

          const multer = require('multer');
            let storage = multer.diskStorage({
                destination: '/public/my-uploads',
                  filename: function (req, file, cb) {
                    cb(null, file.fieldname   '-'   Date.now())
                  }
           });

CodePudding user response:

Use this file name instead of that if you are working on Windows OS, Your code is perfectly working on MAcOS

     filename: (req, file, cb) => {
        cb(
          null,
          new Date().toISOString().replace(/:/g, "-")   "-"   file.originalname
        );

Hope it works for you...

  • Related