0

i want to download file from folder to browser . my first code works fine .the file gets downloaded immediately but when i try to find the file specificly by id it does not works . dont know why ?

///client works

      $.ajax({
      type: 'GET' ,
      url: '/download' ,



      success : function()

      {
        window.open('/download?foo=bar&xxx=yyy');

      }


    });   

/////server works

    app.get('/download', function(req, res) {



      res.download(__dirname + '/uploads/google.png');
    });

////client not works

          $.ajax({
          type: 'GET' ,
          url: '/download/' + id ,



          success : function()

          {
            window.open('/download?foo=bar&xxx=yyy');

          }


        });

/////server not working

      app.get('/download/:id', function(req, res) {

      var id  = req.params.id

      console.log("ddddddddddddddddddddddddddddddddddddddddd")

      console.log(id)

      res.download(__dirname + '/uploads/google' + id  +'.png');
    });

1 Answer 1

1

Because you are passing values as query parameters and not URL parameter from client.

Server side

app.get('/download', function(req, res) {

  var foo  = req.query.foo;
  var xxx = req.query.xxx;

  console.log(foo)
  console.log(xxx)

  //res.download(__dirname + '/uploads/google' + id  +'.png');
});
Sign up to request clarification or add additional context in comments.

1 Comment

how can i download the file ? req.query.id - this way ?

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.