javascript - Multer TypeError: fields.forEach is not a function -


i using multer in node.js express on c9, trying create metadata reader. i've searched quite time, , can't find has run error. error is:

typeerror: fields.foreach not function @ multer.setup (/home/ubuntu/workspace/node_modules/multer/index.js:29:12) @ multermiddleware (/home/ubuntu/workspace/node_modules/multer/lib/make-middleware.js:20:19) @ layer.handle [as handle_request] (/home/ubuntu/workspace/node_modules/express/lib/router/layer.js:95:5) @ next (/home/ubuntu/workspace/node_modules/express/lib/router/route.js:131:13) @ route.dispatch (/home/ubuntu/workspace/node_modules/express/lib/router/route.js:112:3) @ layer.handle [as handle_request] (/home/ubuntu/workspace/node_modules/express/lib/router/layer.js:95:5) @ /home/ubuntu/workspace/node_modules/express/lib/router/index.js:277:22 @ function.process_params (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:330:12) @ next (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:271:10) @ servestatic (/home/ubuntu/workspace/node_modules/express/node_modules/serve-static/index.js:74:16) 

and after trying submit file upload. assume means didn't install correctly, i've tried re-installing in few ways. looks up-to-date:

{  "name": "workspace",   "version": "0.0.0",   "private": true,   "scripts": {     "start": "node ./bin/www"   },   "dependencies": {     "body-parser": "^1.15.2",     "cookie-parser": "~1.4.3",     "debug": "~2.2.0",     "express": "~4.13.4",     "jade": "~1.11.0",     "morgan": "~1.7.0",     "multer": "^1.2.0",     "serve-favicon": "~2.3.0"   } } 

here code:

app.js

var express = require('express'); var app = express(); var path = require('path'); var multer  = require('multer'); var upload = multer({ dest: __dirname + '/public/uploads/'}); var bodyparser = require('body-parser');  app.use(bodyparser.json());  app.use(express.static(path.join(__dirname, 'public')));  app.get('/', function (req, res) {   res.sendfile(path.join(__dirname, 'index.html')); });  app.post('/file-upload', upload.fields('files'), function (req, res, next) {   console.log(req.files);   console.log(req.body); });  app.listen(process.env.port, function () {   console.log('app listening on port ' + process.env.port ); }); 

and front end:

<!doctype html> <html> <head>   <meta charset="utf-8">   <meta http-equiv="x-ua-compatible" content="ie=edge">   <meta name="viewport" content="width=device-width, initial-scale=1">    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <html>   <body>     <div align='center'>       <form method="post" enctype="multipart/form-data" action="/file-upload" name="upload">       <h1>upload file</h1>       <input type="file" id="fileupload"></input>       <h2>view metadata</h2>       <button type="submit" value="submit" id="submit">submit</button>       </form>     </div>    </body> </html> 

removing 'files' upload.fields() gives error

typeerror: cannot read property 'foreach' of undefined 

i trying upload single file, if use

app.post('/file-upload', upload.single('file'), function (req, res, next) {   console.log(req.file);   console.log(req.body); });  // or upload.single() 

my console outputs

undefined {} 

i'm hoping i'm missing simple. i've referenced of these topics, , haven't yet found solution has worked me:

hot multer issues

req files undefined

nodejs-multer-is-not-working

express-multer-cannot-read-property-profileimage-of-undefined

multer-callbacks-not-working

multer-node-eacces-error-on-c9-io

multer-configuration-with-app-use-returns-typeerror

github multer issues thread

was simple. found 5 minutes after posting. i'll leave here in case makes same mistake.

the problem in front end:

<input type="file" id="fileupload"></input> 

needed be

<input type="file" id="file"></input> 

Comments

  1. Javascript - Multer Typeerror: Fields.Foreach Is Not A Function - >>>>> Download Now

    >>>>> Download Full

    Javascript - Multer Typeerror: Fields.Foreach Is Not A Function - >>>>> Download LINK

    >>>>> Download Now

    Javascript - Multer Typeerror: Fields.Foreach Is Not A Function - >>>>> Download Full

    >>>>> Download LINK Hc

    ReplyDelete

Post a Comment

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -