CNode

使用express nodejs 上传图片,但是req请求中没有files这个对象,console.log(req.files)为空

Ggengu发布于12 年前最后回复12 年前5 回复8960 浏览0 收藏

bodyparser的设置 'app.use(bodyParser.json({ uploadDir:'/images/', keepExtensions: true, limit: '50mb'}));

前端的写法是使用formdata传上来的 $("#myfile").change(function(){ var data = new FormData();
var files = $('#myfile')[0].files; \n if(files){ alert(files[0]); data.append('codecsv',files[0]); } $.ajax({
cache: false,
type: 'post',
dataType: 'json',
url:'/upload',
data : data,
contentType: false,
processData: false,
success : function () { }
});
});

大家知道怎么导致的files对象为空么? 在线等回复 急!

查看回复

回复 (5)

G
gengu#1·12 年前

搞定了 var multipart = require('connect-multiparty'); var multipartMiddleware = multipart();

使用这个就可以了

M
MiguelValentine#2·12 年前

用node原生方法去抓包,自己写解析件,EXPRESS不送FILE解析。

R
ringtail#4·12 年前

node-formidable

G
gengu#5·12 年前

@MiguelValentine 你这头像不错

参与回复
登录后即可参与回复。登录