question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected field after match between input name and multer.single

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ilhamfadllahcommented, Aug 11, 2017

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

0reactions
nguyencongvucommented, Jul 12, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found