次のスニペットでは、最初の非同期メソッドのフィールドを検証したいと思います。Node.js、Async、Formidableによるエラー処理
有効でない場合は、すぐにユーザーにエラーを返信したいと思います。
どうすればよいですか?
var form = new formidable.IncomingForm();
async1.series([
function (callback) {
form.parse(req);
form.on('field', function (name, val) {
// Get the fields
});
form.on('fileBegin', function (name, file) {
if (file.name !== "") {
file.path = __dirname + '/upload/' + file.name;
}
});
callback();
},
function (callback) {
form.on('file', function (name, file) {
try {
// Do something with the file using the fields retrieved from first async method
}
catch (err) {
logger.info(err);
}
});
callback();
}
], function (err) {
//the upload failed, there is nothing we can do, send a 500
if (err === "uploadFailed") {
return res.send(500);
}
if (err) {
throw err;
}
return res.status(200);
});
'復帰コールバック(ERR)'すぐにあなたがフィールドをチェックしているかのブロックから、そのコールバックが直接あなたが '送っているあなたの'コールバックハンドラのfunction'を実行しますレスポンスコード。 – Zeeshan