错误提示为:Error: MultipartParser.end(): stream ended unexpectedly: state = START_BOUNDARY
代码为: var form = new formidable.IncomingForm(); form.uploadDir=‘tmp’;
form.parse(request, function(error, fields, files) { if(error) { response.writeHead(500, {“Content-Type”: “text/plain”}); response.write(error + “\n”); response.end(); }else{ console.log(“parsing done : " + files.upload.path); fs.renameSync(files.upload.path, “./tmp/test.png”); response.writeHead(200, {“Content-Type”: “text/html”}); response.write(“received image:<br/>”); response.write(”<img src=’/show’ />"); response.end();
}
});
这是为什么?
感觉是没有POST文件过去,而是直接访问的 /upload
控制台报错信息: console.log("parsing done : " + files.upload.path); ^ TypeError: Cannot read property ‘path’ of undefined
一行代码引发的悲剧 在文件server.js中不应该用request.setEncoding(“utf8”)来手动设置字符编码, 当设置了这个之后,会导致formidable解析出错!!!