使用 connect-multiparty 为上传的文件返回空对象
Empty object returned for uploaded files with connect-multiparty
尝试使用 connect-multiparty
获取文件详细信息,但它返回一个空对象。
var express = require('express'),
bodyParser = require('body-parser'),
app = express();
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
app.use( multipartyMiddleware );
app.post('/testupload1', function(req, res){
var body = req.body; var file = req.files;
console.log(file) // or console.log(body) both empty.
}
表格:
<form action="testupload1" method="post" enctype="multipart/form-data">
<input type="file" name="file"> <br />
<input type="submit" value="Upload">
当我上传 jpeg 文件时,在控制台中得到一个空对象 {}
。我究竟做错了什么?请帮忙。
我想这可能对你有帮助。
var express = require('express'),
bodyParser = require('body-parser'),
app = express();
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/testupload1', multipartyMiddleware, function(req, res){
var file = req.files;
console.log(file)
});
app.get('/file', function (req, res, next) {
res.end('<!DOCTYPE html>'
+ '<html lang="en">'
+ '<head>'
+ '<meta charset="UTF-8">'
+ '<title>Title</title>'
+ '</head>'
+ '<body>'
+ '<form action="testupload1" method="post" enctype="multipart/form-data">'
+ '<input type="file" name="file"> <br />'
+ '<input type="submit" value="Upload">'
+ '</form>'
+ '</body>'
+ '</html>')
});
app.listen(3008);
尝试使用 connect-multiparty
获取文件详细信息,但它返回一个空对象。
var express = require('express'),
bodyParser = require('body-parser'),
app = express();
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
app.use( multipartyMiddleware );
app.post('/testupload1', function(req, res){
var body = req.body; var file = req.files;
console.log(file) // or console.log(body) both empty.
}
表格:
<form action="testupload1" method="post" enctype="multipart/form-data">
<input type="file" name="file"> <br />
<input type="submit" value="Upload">
当我上传 jpeg 文件时,在控制台中得到一个空对象 {}
。我究竟做错了什么?请帮忙。
我想这可能对你有帮助。
var express = require('express'),
bodyParser = require('body-parser'),
app = express();
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/testupload1', multipartyMiddleware, function(req, res){
var file = req.files;
console.log(file)
});
app.get('/file', function (req, res, next) {
res.end('<!DOCTYPE html>'
+ '<html lang="en">'
+ '<head>'
+ '<meta charset="UTF-8">'
+ '<title>Title</title>'
+ '</head>'
+ '<body>'
+ '<form action="testupload1" method="post" enctype="multipart/form-data">'
+ '<input type="file" name="file"> <br />'
+ '<input type="submit" value="Upload">'
+ '</form>'
+ '</body>'
+ '</html>')
});
app.listen(3008);