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?