📅  最后修改于: 2022-03-11 15:01:08.653000             🧑  作者: Mango
const multer = require('multer');
const {Duplex} = require('stream'); // It's a Native Node Module
const fs = require('fs');
const readXlsxFile = require('read-excel-file/node')
const storage = multer.memoryStorage();
const upload = multer({
storage: storage
});
function bufferToStream(bufferIn) {
let duplex = new Duplex();
duplex.push(bufferIn);
duplex.push(null);
return duplex;
}
app.post('/api/endpoint_name', upload.single('file'), function(req, res) {
const file_buffer = req.file['buffer'];
const file_stream = bufferToStream(file_buffer);
const read_stream = fs.createReadStream(file_stream);
readXlsxFile(read_stream)
.then(function(rows) {
console.log('Rows in the Excel : ', rows);
});
});