'stream huge excel file using exceljs in node
I am using exceljs
to stream files. Unfortunately, when file is too large it fires 502 bad gateway error after 2 minutes(I've increased it from 1 minute in nginx). As I understand, streaming large files should not fire timeout.
const specification_abc_xyz = [
{ header: "", key: "index", width: 6 },
{ header: "1", key: "name", width: 120 },
{ header: "2", key: "share", width: 23 },
{ header: "3", key: "cum_share", width: 25 },
{ header: "4", key: "coeff", width: 29 },
{ header: "5", key: "abc", width: 10 },
{ header: "6", key: "xyz", width: 10 },
];
knexPromise({}).then((abc_xyz) => {
var options = {
stream: res, // write to server response
useStyles: false,
useSharedStrings: false,
};
let workbook = new Excel.stream.xlsx.WorkbookWriter(options);
let worksheet = workbook.addWorksheet("Tutorials");
res.status(200);
res.setHeader("Content-disposition", "attachment; filename=db_dump.xls");
res.setHeader("Content-type", "application/vnd.ms-excel");
worksheet.columns = specification_abc_xyz;
abc_xyz.rows.forEach((count, idx) => {
count.index = idx + 1;
worksheet.addRow(count).commit();
});
worksheet.commit();
return workbook.commit().then(function () {
res.status(200).end();
});
Maybe I am using streaming wrong. Is it possible to stream large files without increasing timeout? Thanks in advance.
Solution 1:[1]
"As I understand, streaming large files should not fire timeout."
It sounds like its not. It sounds like your gateway has a timeout that when any request exceeds that amount of time it closes the connection. Streaming of the file is not throwing a timeout, its just taking too long so the gateway closes the connection. You need to either speed up the reading and writing of the file or else extend your gateway timeout.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ray |