[Solved-2 Solutions] Express res.sendfile throwing forbidden error
Error Description:
- We have this code:
- However, it throws this error:
Solution 1:
- It's because of the relative path; the "../" is considered malicious. Resolve the local path first, then call res.sendfile. You can resolve the path with path.resolve beforehand.
Solution 2:
- The Express documentation suggests doing it a different way:
- The root option seems to set ./ as the root directory of your project. So we cannot tell where the file is in relation to the project root, but if your temp folder is there, you can set ./temp as the root for the file you're sending.