0

I've been stuck on this for a while now. For some reason I can't get this to work. What I'm trying to do is get the name of downFile:

app.get('/download', function(req, res){
 var selectedFile = req.body.downFile;
 var file = __dirname + '/uploads/' + filename;

  var filename = path.basename(file);
  var mimetype = mime.lookup(file);

  res.setHeader('Content-disposition', 'attachment; filename=' + filename);
  res.setHeader('Content-type', mimetype);

  var filestream = fs.createReadStream(file);
  filestream.pipe(res);
});

HTML: enter image description here

If anyone knows how to properly get the name of "downFile" I would much appreciate.

3
  • from where you are getting filename in var file = __dirname + '/uploads/' + filename; ? Commented Sep 14, 2015 at 20:37
  • By name of "downFile" do you mean the value of the input with name="downFile"? Commented Sep 14, 2015 at 20:40
  • I want "var selectedFile = req.body.downFile;" to return the value of downFile yes. When I use req.body.downFile it returns an undefined property. Commented Sep 14, 2015 at 20:43

1 Answer 1

1

req.body.downFile would work if you are passing the value of an input called downFile via POST. But since you are working with file uploads, POST won't help you a lot and should instead take a look at one of the following modules:

http://expressjs.com/api.html#req

In Express 4, req.files is no longer available on the req object by default. To access uploaded files on the req.files object, use a multipart-handling middleware like busboy, multer, formidable, multiparty, connect-multiparty, or pez.

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.