這裏有什麼問題?節點js文件上傳出錯
我有文件節點js文件上傳動作和另一個HTML文件
文件到upload.js
var formidable = require('formidable');
var http = require('http');
var form = new formidable.IncomingForm();
http.createServer(function(req, res){
form.parse(req, function(err, fields, files){
console.log(files.filetoUpload.path);
});
}).listen(3002);
fileUpload.html
<body>
<form action="" enctype="multipart/form-data" method="post">
<input type="file" name="filetoUpload">
<input type ="submit" value="Upload">
</form>
</body>
Exception has occurred: Error TypeError: Cannot read property 'path' of undefined at d:\CUBIC\UI\asg\1\FileUpload.js:9:39 at IncomingForm. (d:\CUBIC\UI\asg\1\node_modules\formidable\lib\incoming_form.js:105:9) at emitNone (events.js:86:13) at IncomingForm.emit (events.js:185:7) at IncomingForm._maybeEnd (d:\CUBIC\UI\asg\1\node_modules\formidable\lib\incoming_form.js:553:8) at Object.end (d:\CUBIC\UI\asg\1\node_modules\formidable\lib\incoming_form.js:239:12) at IncomingMessage. (d:\CUBIC\UI\asg\1\node_modules\formidable\lib\incoming_form.js:130:30) at emitNone (events.js:86:13) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12)
當你記錄'files'時你會得到什麼? – turmuka
錯誤消息試圖告訴你'files.filetoUpload'的屬性'path'沒有定義。也許'err'被填充?你有沒有檢查它? –
在files.filetoUpload.path中包含fakepath示例C:\\ Users \\ SYEDAY〜1 \\ AppData \\ Local \\ Temp \\,它不存在於system.So中,這就是爲什麼它顯示爲undefined。 –