I am trying to download a file from my nodeJS server, however opening the files afterwards is not possible. For example: The original 15kb JPG file will be 24kb when downloaded and impossible to show.
upload:
if (fs.existsSync(filePath)) {
res.download(filePath);
readStream.pipe(res);
} else {
return res.status(404).json({msg: "Failed to load file"});
}
download:
import fileDownload from "js-file-download";
const getFile = async (filename) => {
const headers = {
'responseType': 'blob',
'x-access-token': JSON.parse(localStorage.getItem('user')).token
}
await axios.post(getFileRoute, {
filename: filename
}, {headers: headers})
.then((response) => {
fileDownload(response.data, filename);
});
}
The picture preview is also shown in the network tab of google chrome's inspect. Thank you for your help!