how to upload file and get it content in node js

烂漫一生 提交于 2020-01-07 08:07:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!