Unexpected field after match between input name and multer.single
See original GitHub issueI know that this question already asked many times, but after I looked the answers of existing issues still doens’t work in my code. I’m using multer 1.3.0. My snippet code as follows:
Router
var multer = require('multer'),
bodyParser = require('body-parser'),
path = require('path');
router.post("/kegiatan", multer({ dest: './uploads/'}).single('foto'), siswa_controller.tambah_kegiatan);
View
form.ui.form(method='post',action='/member/siswa/kegiatan', enctype='multipart/form-data')
.field
label Judul Kegiatan
input(type='text', name='judul', placeholder='Tuliskan judul kegiatan')
.field
label Kategori
select.ui.search.dropdown(name='kategori',id='selectKategori')
option(value='') Pilih kategori kegiatan
.field
label Berkas Foto
input(type='file',name='foto')
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
node.js - Node Multer unexpected field - Stack Overflow
The first router used the name field with view one and its file name was "imgLoading". The second view had another name the...
Read more >Getting MulterError: unexpected field even when field name ...
I'm using fetch and FormData to upload a file to a nodejs server using multer, and I'm getting the error "MulterError: unexpected field" ......
Read more >Fix "Unexpected field" Error From Multer - YouTube
00:29 - File input name doesn't match multer configuration 01:15 - Multiple file uploads 01:49 - Finding the unexpected field 02:20 ...
Read more >Fix "Unexpected field" Error From Multer - DEV Community
If the user change the input name in dom. Your server will crash.
Read more >NestJS: Type-safe File Uploads - notiz.dev
Nest uses multer for handling file uploads using the multipart/form-data ... must match the name of the properties field in the @ApiBody() ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Finally, I’ve solved the problem. I didn’t realize that I wrote twice for require multer(In controller and app.js). So should be sure that just once to write require the multer library. In my case just in controller and it works to upload file. And for parsing file request just type req.file not req.foto in my case.
Sorry for my fault, Thank you anyway @LinusU
I spent all days to check and got same stupid mistake as you. For one who got “Unexpected field” error although fieldname matched (or KEY in Postman matched), please check again in your app.js (or main.js…) whether you declare and init Multer before
Thanks