Skip to content

Instantly share code, notes, and snippets.

@pokisin
Last active January 28, 2021 15:44
Show Gist options
  • Save pokisin/9d8e2149073849e628c795f720dd860d to your computer and use it in GitHub Desktop.
Save pokisin/9d8e2149073849e628c795f720dd860d to your computer and use it in GitHub Desktop.
Cannot app.use(multer). “requires middleware function” error
------------------- SOLVED --------------------------
You need to use app.use(multer({dest:'./uploads/'})) in the form of one of these:
app.use(multer({dest:'./uploads/'}).single(...));
app.use(multer({dest:'./uploads/'}).array(...));
app.use(multer({dest:'./uploads/'}).fields(...));
ie:
app.use(multer({dest:'./uploads/'}).single('file'));
And be sure to have something like:
<form action="/file_upload" enctype="multipart/form-data" method="post">
<input type="file" name="file">
<input type="submit" value="Upload file">
</form>
In your html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment