var fs = require(‘fs‘)
var multer = require(‘multer‘)
var path = "./public/static/upload";
// if (!fs.existsSync(path)) {
// fs.mkdirSync(path)
// }
var storage = multer.diskStorage({
destination: function (req, res, cb) {
cb(null, path);
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
var upload = multer({
storage: storage,
limits: {
fieldNameSize: ‘10M‘
}
})
exports.singleUpload = function (req, res) {
s = uploadResource.single(‘imgUpload‘);
s(req, res, function (err) {
if (err) {
res.send({
‘status‘: ‘failed‘
})
} else {
res.send({
‘status‘: ‘ok‘
})
}
})
}
4. api增加到router
router.post(‘/getFile‘,upload.singleUpload)
其他补充:如果是excel 换成
accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
api里面解析的时候 用到 var xlsx = require(‘xlsx‘);//自己了解