I'm aware that this has been asked before, but I'm not able to get it to work. The backend is sending the file using wb.write('filename.xlsx', res) but on the frontend, I just get an object response. How do I get the browser to download the .xlsx file instead?
// express backend
const x1 = require('excel4node');
router.get('/excel', async (req, res) => {
const wb = new x1.Workbook();
// do some stuff
wb.write('excel.xlsx', res);
});
// frontend
axis(config).then((res) => {
// What do I do here? res is an object. How do I handle this response so that the browser is downloading the file instead?
}).catch(...);
Answer for front-end side,
You can write the axios code as follows:
Backend:
You need to make sure that you configured CORS properly, For your reference, please check the code below.
At front-end side, we can extract file name along with extension from content disposition header. This is the same name that we set
wb.write('Excel.xlsx', res);