搜尋

首頁  >  問答  >  主體

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">');
    });
巴扎黑巴扎黑2864 天前731

全部回覆(2)我來回復

  • 伊谢尔伦

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

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

    這個貼文裡面可能有你需要的東西,我也遇到了這樣的問題

    回覆
    0
  • PHPz

    PHPz2017-04-17 12:03:59

    如果是看這個網址www.nodebeginner.org/index-zh-cn.html學習的話:
    應該把sever.js裡下面這行程式碼註解掉就可以了
    request.setEncoding(" utf8");

    回覆
    0
  • 取消回覆