简体   繁体   English

stream 巨大的 excel 文件在节点中使用 exceljs

[英]stream huge excel file using exceljs in node

I am using exceljs to stream files.我正在使用exceljs到 stream 文件。 Unfortunately, when file is too large it fires 502 bad gateway error after 2 minutes(I've increased it from 1 minute in nginx).不幸的是,当文件太大时,它会在 2 分钟后触发 502 bad gateway 错误(我已经从 nginx 中的 1 分钟增加了它)。 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?是否可以在不增加超时的情况下处理 stream 大文件? Thanks in advance.提前致谢。

"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.您需要加快文件的读取和写入速度,或者延长网关超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM