0

I've written a react app that makes use of the FilePond file uploader but am having trouble getting multer to accept the request from filepond, it always returns a 500 error.

If I use a standard file upload control the request is accepted by the server and the file uploads fine.

Does anyone have any thoughts on what might be causing this?

Thanks

This is my server.js code:

    var express = require('express');
var app = express();
var multer = require('multer')
var cors = require('cors');
app.use(cors())
var storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, 'public')
    },
    filename: function (req, file, cb) {
      cb(null, Date.now() + '-' +file.originalname )
    }
  })

  var upload = multer({ storage: storage }).array('file')

app.get('/',function(req,res){
    return res.send('Hello Server')
})
app.post('/upload', function(req, res) {

    upload(req, res, function (err) {

        if (err instanceof multer.MulterError) {
            return res.status(500).json(err)
          // A Multer error occurred when uploading.
        } else if (err) {
            return res.status(500).json(err)
          // An unknown error occurred when uploading.
        } 

        res.send([req.files[0].filename]);


        return res.status(200).send(req.file)
        // Everything went fine.


      })
});

app.listen(8000, function() {
    console.log('App running on port 8000');
});
  • go and check/create logs on backend side. then update the question with that logs – Harsh Patel Mar 06 '19 at 12:23
  • Thanks, how would I do that? –  Mar 06 '19 at 12:30
  • just add console.log(err) – Harsh Patel Mar 06 '19 at 12:30
  • that's done but I see nothing in the console [code]app.post('/upload', function(req, res) { upload(req, res, function (err) { if (err instanceof multer.MulterError) { console.log(err); return res.status(500).json(err) } else if (err) { console.log(err); return res.status(500).json(err) } res.send([req.files[0].filename]); console.log('worked'); return res.status(200).send(req.file) }) });[/code] –  Mar 06 '19 at 12:38

0 Answers0