Good day! I am trying to upload a file to the server, the Internet is replete with a bunch of examples of how to do this. The way through multer seemed quite simple, but an error.

Here is a html code snippet:

<form action="/data" method="POST" enctype="multipart/form-data" > <input type="file" name="filefield" /> <input type="submit" /> </form> 

Here is a js code snippet:

 import express from 'express'; const app = express(); var multer = require('multer'); var upload = multer({ dest : 'src/uploads/'}); app.post('/data', upload.single('filefield'), function (req, res, next) { res.send(req.files) }); 

The problem is that it generates an Unresolved function or method single () error.

Multer is using the latest version. What could be wrong? Or maybe there is a simpler way?

  • and if to register upload.any () - then the file comes? - C.Raf.T
  • there will be an unresolved function or method any () error. - Mc Kaktus
  • try installing the previous version of multer:" ^1.2.0" - C.Raf.T
  • I tried to roll back to earlier ones, the same problem - Mc Kaktus
  • and what express and node? - C.Raf.T

1 answer 1

In what cant with single () is not clear, but the file was able to download via express-fileupload:

 var fileUpload = require('express-fileupload'); app.use(fileUpload()); app.post('/data', function (req, res, next) { var sampleFile; if (!req.files) { res.send('No files were uploaded.'); return; } sampleFile = req.files.sampleFile; sampleFile.mv('./uploads/filename.png', function(err) {}); next(); }); 

And yes, this method did not work either, until I fixed the enctype on encType. Perhaps there were conflicts with a bunch of other libraries for downloading files that I installed, trying different methods. I deleted them too.