Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Upload different files in different folders using Multer in NodeJs

const multer = require('multer')const storage = multer.diskStorage({destination: (req, file, cb) => {  const { userId } = req.body  const dir = ./uploads/${userId}  fs.exists(dir, exist => {  if (!exist) {    return fs.mkdir(dir, error => cb(error, dir))  }  return cb(null, dir)  })},filename: (req, file, cb) => {  const { userId } = req.body  cb(null, UserId-${userId}-Image-${Date.now()}.png)}})const upload = multer({ storage })
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #Upload #files #folders #Multer #NodeJs
ADD COMMENT
Topic
Name
5+4 =