Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
req.param.id brings "undefined"

Getting req.param undefined

Hi, I have a similar error to the one above.

server.get('/:file_id', function(req , res) {
  var file_id = req.params.id;
  console.log(file_id);
  gfs.files.find({_id: file_id}).toArray(function (err, files) {
    if (err) {
      res.json(err);
    }
    if (files.length > 0) {
      var mime = files[0].contentType;
      var filename = files[0].filename;
      res.set('Content-Type', mime);
      res.set('Content-Disposition', "inline; filename=" + filename);
      var read_stream = gfs.createReadStream({_id: file_id});
      read_stream.pipe(res);
    } else {
      res.json(file_id+ '  This file does not exist.');
    }
  });
});

Below is a ejs file that gets file_id to server.

<div class="card card-body mb-3">
    <%= file.filename %>
          <form action="/:<%= file._id %>" method="get">
            <input type="submit" value="DOWNLOAD" class="btn btn-primary btn-block">
          </form>
  </div>

What I get from this code is : "undefined This file does not exist." I think the problem lies on req.params.id but am not sure where to fix.

Thank you.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!