如何上传文件并在Node js中获取内容 [英] how to upload file and get it content in node js
问题描述
我正在尝试上传xsls文件,并尝试将其内容转换为JSON并显示在控制台中. 我正在使用此插件上传文件 https://www.npmjs.com/package/express-fileupload 我对此做一个简单的演示.
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
我在通过此sample file
使用我的服务时 https://gofile.io/?c=2wBegC
它显示了binary
不是JSON或内容
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
});
我认为我需要将binary
转换为某些json对象
I think i need to convert binary
to some json object
推荐答案
您可以尝试excel2Json:
You could try excel2Json:
npm install excel2Json --save
然后:
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
});```
这篇关于如何上传文件并在Node js中获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!