Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

handle multer error json

const upload = multer({
    storage: storage,
    limits: {
        fileSize: 1024 * 1024 * 5
    },
    fileFilter: (req, file, cb) => {
        if (file.mimetype == "image/png" || file.mimetype == "image/jpg" || file.mimetype == "image/jpeg") {
            cb(null, true);
        } else {
            return cb(new Error('Invalid mime type'));
        }
    }
});

const uploadSingleImage = upload.single('image');

app.post('/upload', function (req, res) {

    uploadSingleImage(req, res, function (err) {

        if (err) {
            return res.status(400).send({ message: err.message })
        }

        // Everything went fine.
        const file = req.file;
        res.status(200).send({
            filename: file.filename,
            mimetype: file.mimetype,
            originalname: file.originalname,
            size: file.size,
            fieldname: file.fieldname
        })
    })
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: EXPRESS APP REGISTER HANDLEBARS VIEW ENGINE 
Javascript :: nuxt history back 
Javascript :: emergency food 
Javascript :: quasar router authentication 
Javascript :: json schema eg 
Javascript :: javascript remove elements from array with value 
Javascript :: react hook form submit outside form 
Javascript :: how to pass a component as a prop in react 
Javascript :: mongoose encrypt database using mongoose encrypt package 
Javascript :: Javascript swap old and new method 
Javascript :: how to test usehistory in jest 
Javascript :: adobe target triggerview 
Javascript :: number of edges between set of nodes networkx 
Javascript :: javascript tag 
Javascript :: reactjs facebook login popup trigger on load page 
Javascript :: Half or Right Triangle star pattern in JavaScript 
Javascript :: javascript Use clearTimeout() Method 
Javascript :: ternary 
Javascript :: date difference without weekends using moment js 
Javascript :: crud in nodejs sequilize 
Javascript :: vue nexttick 
Javascript :: JSON schema enumerated type 
Javascript :: javascript string to boolean 
Javascript :: jquery steps disable finish button 
Javascript :: react useeffect on change props 
Javascript :: mongoose discriminator 
Javascript :: JavaScript Creating Symbol 
Javascript :: jquery validation date min max 
Javascript :: js fit window to content 
Javascript :: update node two versions mac 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =