developerasun / myCodeBox-web

Open source code box for web developers.
Apache License 2.0
5 stars 0 forks source link

[BUG] Javascript/multer: The "path" argument must be of type string. Received undefined #251

Open developerasun opened 2 years ago

developerasun commented 2 years ago

issue : Node js multer file upload not working

place : describe where the bug happened

myJavascript/backend/miniProjects/uploadFiles

const storage = multer.diskStorage({
    // set where to save file
    destination: (req, file, cb) => {
        cb(null, 'upload/') // takes error and path to store file
    },
    // set filename
    filename: (req, file, cb) => {
        cb(null, file.filename) // takes error and filename
    }
})

const upload = multer({ storage })

screenshot : attach a screenshot showing the bug

path-type-string

label : add propel lables for the bug

developerasun commented 2 years ago

solution: set filename string like below

multer.diskStorage( {

    filename: (req, file, callback) => {
        const { originalname } = file // or 
        const filename = "myFile" // string
        callback(null, originalname || filename)
    }
})