下面代码里使用app.use(bodyParser.json());app.use(bodyParser.urlencoded({ extended: false }));这应该已经解析了请求体啊,为什么req.files还是undefined?var express = require('express');var bodyParser = require('body-parser');var multiparty = require('multiparty');var app = express();app.listen(3000);// view engine setupapp.set('views', path.join(__dirname, 'views'));app.set('view engine', 'ejs');app.set('photos',__dirname+'/public/photos');app.use(bodyParser.json());app.use(bodyParser.urlencoded({ extended: false }));app.use(express.static(path.join(__dirname, 'public')));app.get('/upload',photos.form);app.route('/upload').post(function(req,res){ var multiparty = require('multiparty'); var form = new multiparty.Form();//新建表单 //设置编辑 form.encoding = 'utf-8'; //表单解析 form.parse(req, function(err,fields,files) { //报错处理 if(err){ return; } console.log("files: ", files); var oldpath=files.imgFile[0]['path']; });});module.exports = app;
添加回答
举报
0/150
提交
取消