node.js - 上传图片时, form.parse回调里的files对象是个空对象 ,求大神指点
巴扎黑
巴扎黑 2017-04-17 12:01:59
0
2
729

不知道有哪些情况会导致files为空,fields 有值, 值为 {upload: 'test.png'}, test.png就是我上传的那张图片,请大家帮我看看,不甚感激

    var form = new formidable.IncomingForm();
    form.parse(request, function (error, fields, files){
        console.log(files);
        fs.renameSync(files.upload.path, 'temp/test.png');
        response.writeHead(200,{'Content-Type': 'text/html'});
        response.end('<img src="/show">');
    });
巴扎黑
巴扎黑

reply all(2)
伊谢尔伦

https://cnodejs.org/topic/50234890f767cc9a51f88481

This post may have what you need, I also encountered such a problem

PHPzhong

If you are learning from this website www.nodebeginner.org/index-zh-cn.html:
You should just comment out the following line of code in sever.js
request.setEncoding(" utf8");

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template