0

I know I can download static files from frontend with

<a href="/path/fileName" download>MyDocument</a>

, but I need to download dynamic files that can be uploaded and deleted by the user in the future, so I need to use the backend for it. I found that I can use res.download for it, so I was thinking about something like this in the backend:

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

  const fileName = req.query.fileName;
  const path = "./assets/" + fileName;

  res.download(path);
})

Usually I use Axios to give parameters to Express in the req.query, but how does it look like if I want to use a hyperlink to trigger the download? Do I still need to use Axios, or can the hyperlink call the backend right away?

1
  • What you're trying to do is ok Commented Apr 4 at 12:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.