[英]how to upload file and get it content in node js
我正在尝试上传 xsls 文件并尝试将其内容转换为 JSON 并在控制台中显示。 我正在使用这个插件上传我的文件https://www.npmjs.com/package/express-fileupload我做了一个简单的演示。
https://codesandbox.io/s/flamboyant-payne-p7chg
我使用此sample file
https://gofile.io/?c=2wBegC使用我的服务时,它向我显示binary
而不是 JSON 或内容
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 对象
尝试使用 express-fileupload npm 包,它真正帮助你需要的是这个中间件
const fileUpload = require('express-fileupload');
app.use(fileUpload({
createParentPath: true
}));
你可以试试 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
});```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.