问题
I am trying to upload xsls file and try to convert its content in JSON and show in console. I am using this plugin to upload my file https://www.npmjs.com/package/express-fileupload I make a simple demo of this.
https://codesandbox.io/s/flamboyant-payne-p7chg
I when used my service using this sample file
https://gofile.io/?c=2wBegC
it shows me binary
not JSON or content
app.use(upload()); // configure middleware
app.get("/abc", function(req, res) {
res.send({ test: "sss" });
});
app.post("/upload", function(req, res) {
console.log("ssss");
console.log(req.files);
});
app.listen(PORT, function() {
console.log("Express server listening on port ", PORT); // eslint-disable-line
});
I think i need to convert binary
to some json object
回答1:
You could try excel2Json:
npm install excel2Json --save
Then:
const excel2Json = require('excel2json');
excel2Json('sample.xls', (err, output) => {
// do stuff with your outputJSON
});
// Or with additional options
excel2Json('../test/sample.xls', {
'convert_all_sheet': false,
'return_type': 'File',
'sheetName': 'survey'
}, (err, output) => {
// do stuff with your outputJSON
});```
来源:https://stackoverflow.com/questions/57892484/how-to-upload-file-and-get-it-content-in-node-js