When trying to utilize the res.download() method for downloading specific files from a server, there is an issue where triggering the res.download does not redirect the client to the correct URL. The files intended for download are located in a directory set statically.
The relevant backend code snippet is as follows:
app.get("/downloadfile", function(req,res){
var file = req.query.file;
var currentpath = req.query.currentpath;
console.log("SENDING FILE: " + file + " at: " + currentpath);
//file = file.substring(20, file.length)
console.log(file);
console.log(currentpath + "/" + file);
res.download(currentpath + "/" + file, file);
})
Upon running this section of code, the terminal output is as below:
SENDING FILE: Matthew Haywood CV.pdf at: /media/pi/ELEMENTS B//Matt Haywood/Uni Work
Matthew Haywood CV.pdf
/media/pi/ELEMENTS B//Matt Haywood/Uni Work/Matthew Haywood CV.pdf
The provided path for the res.download function appears accurate based on the terminal output and no errors were observed in the front end code execution.
This Safari route leads to the following outcome when accessed:
https://i.sstatic.net/mlhtx.png
The concern arises as to why res.download directs to /path_to_file/your_file.pdf/ rather than server/path_to_file/your_file.pdf?
Manually visiting the URL results in successful file downloads, however, the issue lies in the res.download() function redirecting to an incorrect URL.