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.

Cant get the middleware work in express 4

See original GitHub issue

I am just following the readme tutorial and encountered the problem of

Error: Unexpected field 
    at makeError (*\node_modules\multer\lib\make-error.js:12:13)

my code look like this:

var express = require('express');
var app = express();

var multer = require('multer');
var upload = multer({ dest: './uploads/'});

app.post('/image',upload.single('avatar'), function (req, res) {
    var image = req.body;
    res.status(204).end()
});

my client is angular from the tutorial :https://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs

I cant find the solution can you help me?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

43reactions
LinusUcommented, Jul 19, 2015

What is the field name of the file uploaded? <input type="file" name="THISVALUE" />

The code you are using is expecting it to be avatar.

6reactions
rakeencommented, Apr 2, 2016

Got it. I was using ng2-file-upload to send the XHR request. By default they set the name of all the fields to file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node / Express 4 middleware not working - Stack Overflow
An important thing to know about Express middleware is that it's called in order of declaration. If any of the declared middleware handles...
Read more >
Writing middleware for use in Express apps
Middleware functions are functions that have access to the request object ( req ), the response object ( res ), and the next...
Read more >
Complete Guide to Express Middleware - Reflectoring
We can use middleware functions for different types of processing tasks required for fulfilling the request like database querying, making API ...
Read more >
Express/Node introduction - Learn web development | MDN
You can use Express middleware to add support for cookies, sessions, and users, getting POST / GET parameters, etc.
Read more >
Handle GET and POST Request in Express - CodeForGeek
GET and POST is two common HTTP Requests used for building REST APIs. ... Express requires an additional middleware module to extract incoming...
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