Monday 26 June 2017

Handling multer file validation errors

Hi,I have the following to handle file uploads: app.post('/api/upload', multer({ fileFilter: function(req, file, callback) { if(path.extname(file.originalname) !== '.csv') { return callback(new Error('Only csv files allowed!')); } callback(null, true) }, dest: './uploads' }).single('csvFile'), function(req, res) { csvParser(req, res); }); What I needed is to pass the error message 'Only csv files allowed!' to my front end (vuejs). The code callback(new Error('Only csv files allowed!') sends a response to the client, with the response body containing an entire HTML document detailing the error.Is there a way to extract only the error message 'Only csv files allowed!' on the client side?

Submitted June 26, 2017 at 05:46PM by raccoonranger73

No comments:

Post a Comment