Multer returning undefined for svg image file upload

Viewed 167

I want to upload svg image to my NodeJs - Express server from React ( using Redux ). I am using signature_pad npm module for drawing signatures. This is code in React:

        formData.append('contractId', contractId);
        formData.append('svg_signature',signaturePad.toDataURL("image/svg+xml"));

        dispatch(sign_contract_action(formData));

This is what signaturePad.toDataURL("image/svg+xml") looks like:

 data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDov...

This is my express router:

router.post('/sign-contract',upload_file.single('svg_signature'),save_svg_signature);

And this is the part where I want to receive svg image file and store it but it is undefined:

const save_svg_signature = async (req,res,next) => {
    const { file } = req;
    const { contractId } = req.body;
    console.log(contractId); // works
    console.log(file); // undefined
};
0 Answers
Related