我需要检查是否在服务器端附加了Realy文件。我正在使用busboy处理文件上传。
我在这里处理文件:
req.busboy.on('file', function (teste, file, filename) {
console.log("Uploading: " + filename);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fstream = fs.createWriteStream(__dirname + '../../../curvas/' + sha1 + "/" + filename);
var chart = new Chart();
chart.sha1 = sha1;
file.pipe(fstream);
fstream.on('close', function (err) {
if (err) {
console.log("Erro: " + err);
}
// salvar as informações no banco.
chart.save(function (err) {
if (err) {
console.log(err);
} else {
console.log("Arquivos recebidos com sucesso.");
}
});
});
});
当我上传文件时,服务器会像假定的那样响应,但是,如果我不附加任何文件,则会显示此错误:
_stream_readable.js:628
dest.end();
^
TypeError: Cannot read property 'end' of undefined
at IncomingMessage.onend (_stream_readable.js:628:10)
at Object.onceWrapper (events.js:273:13)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
有人知道如何处理此错误吗?