showing results for - "how we can upload all other type of image through express file uploader"
Xavier
12 Oct 2017
1app.post('/upload-profile-pic', (req, res) => {
2    // 'profile_pic' is the name of our file input field in the HTML form
3    let upload = multer({ storage: storage, fileFilter: helpers.imageFilter }).single('profile_pic');
4
5    upload(req, res, function(err) {
6        // req.file contains information of uploaded file
7        // req.body contains information of text fields, if there were any
8
9        if (req.fileValidationError) {
10            return res.send(req.fileValidationError);
11        }
12        else if (!req.file) {
13            return res.send('Please select an image to upload');
14        }
15        else if (err instanceof multer.MulterError) {
16            return res.send(err);
17        }
18        else if (err) {
19            return res.send(err);
20        }
21
22        // Display uploaded image for user validation
23        res.send(`You have uploaded this image: <hr/><img src="${req.file.path}" width="500"><hr /><a href="./">Upload another image</a>`);
24    });
25});
26