1

I want to upload a file with a form like this (JADE) :

form(action="/file-upload", name="upload", method="post", enctype="multipart/form-data")
    input(type="file", name="theFile")
    input(type="submit", name="Upload")

this is my app.js :

app.use(express.methodOverride());
app.use(express.multipart());
app.use(express.bodyParser());

and this is how I handle the requests:

app.post('/file-upload',function(req,res){
   console.log('FIRST TEST: ' + JSON.stringify(req.files));
   console.log('second TEST: ' +req.files.theFile.name);
});

and this is my Node.js Console :

FIRST TEST: undefined
TypeError: Cannot Read Property 'theFile' of undefined....etc....

oh and by the way there is a warning from Connect module :

connect.limit() will be removed in connect 3.0
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives

What am I do wrong here ? i have follow advise from here, here, here with nothing works. Thanks for help.....

UPDATE: i just added LOGGER to my apps with result, so it's seems that i got the request:

127.0.0.1 - - [Wed, 19 Feb 2014 11:02:11 GMT] "POST /file-upload HTTP/1.1" 500 - 
"http://localhost:3000/admin/news-add" "Mozilla/5.0 (Windows NT 6.1; WOW64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"
3
  • 1
    Express has an example for file upload here and according to it it looks like your doing things right on the server backend. Try adding app.use(express.logger('dev') to enable some log output to see what you are actually receiving. Commented Feb 19, 2014 at 10:17
  • just add logger as you suggested. it seems fine, server got the POST request and still 'undefined' Commented Feb 19, 2014 at 11:06
  • See stackoverflow.com/questions/19959708/… Commented Feb 19, 2014 at 11:52

1 Answer 1

3

I see now... i have

app.use(express.multipart());
app.use(express.bodyParser());
app.use(express.methodOverride());

after app.use(app.router); where it should be declared before, like this :

app.use(express.multipart());
app.use(express.bodyParser());
app.use(express.methodOverride())
app.use(app.router);

now, it's work like a charm....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.