search

Home  >  Q&A  >  body text

node.js - 上传图片时, form.parse回调里的files对象是个空对象 ,求大神指点

不知道有哪些情况会导致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">');
    });
巴扎黑巴扎黑2779 days ago704

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:03:59

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

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

    reply
    0
  • PHPz

    PHPz2017-04-17 12:03:59

    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");

    reply
    0
  • Cancelreply