Send Multer error to React.js

10 views
Skip to first unread message

foysal foysal

unread,
Apr 4, 2019, 12:36:21 AM4/4/19
to nodejs

I am trying to Upload file using multer, I would like to send error to React. My code is like below



const fileFilter = (req, file, cb) => {
        if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
            cb(null, true);
        } else {
            cb(new Error('Try to upload .jpeg or .png file.'), false);
        }
    };

const upload = multer({
        storage: storage,
        limits: {
            fileSize: 1024 * 1024 * 5
        },
        fileFilter: fileFilter
    }).single('addressImage');


upload(req, res, function(error) {
        if (error) {
            // An error occurred when uploading
            res.status(500).json({
                error // I would like to send error from here, But I am not getting error in React.
            });
            return;
        }
    });

Kawa1l g1rl

unread,
Apr 5, 2019, 1:47:18 AM4/5/19
to nod...@googlegroups.com
ok. but i am beginner. so i have some time to give solution to you. please waiting some time..

2019년 4월 4일 (목) 오후 1:36, foysal foysal <now...@gmail.com>님이 작성:
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/87f28226-ccf5-40c8-940c-e4413835af01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages