I don't know why it's happening, but it's really annoying. I expected the file to be downloaded according to the express docs. I have the next code:
//in react (App.js)
download = () => {
const { images, target } = this.state;
const filename = images.find(img => img.id === target).filename;
fetch('http://localhost:3001/download', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({filename})
})
}
//in express (server.js)
app.post('/download', (req, res) => {
var file = '../public/images/' + req.body.filename;
res.download(file, req.body.filename);
});
The folder structure:
-server
|-server.js
-public
|-images
|-a.jpg
|-b.jpg
-src
|-App.js
Nothing's happening, errors not shown. Any ideas?