0

I'm using latest NodeJS and ExpressJS to write a small app. Currently I stuck on uploading a file. :>

routes are configured this way

app.get('/Share', share.index);
app.post('/Share/Process', share.processFile);

The index view looks like the following

form.form-horizontal(action='/Share/Process', method='post')
  legend share a file
  div.control-group
    label.control-label(for='item[actual]') File
    div.controls
      input(type='file', name='item[actual]', required='required')

When I follow the ExpressJS API documentation, I should have access to the file, by using req.files, which is undefined within the share.processFile method

exports.processFile = function(req,res){
  console.log(req.files); // undefined
  console.log(req.body.item.actual); // filename as string
  res.render('share/success', {navigation: { shareClass : 'active'}, downloadKey: 'foo'});
};
2
  • Are you sure you're invoking express.bodyParser before you define your routes (otherwise req.files won't get set)? Commented Sep 18, 2012 at 10:15
  • yes bodyParser is invoked w/o any parameters Commented Sep 18, 2012 at 10:52

1 Answer 1

2

Try changing the form encoding to multipart/form-data, IIRC this should be set for transferring files.

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.