スキッパーアップロード機能で、ファイル保存を行うべきではないなどの制約を検知した場合、ファイル保存をキャンセルすることはできますか?
次のようなコードのスニペットがあります。
req
.file("multimedia")
.upload({
// Destination directory
dirname : dirName,
// Maximum image size in bytes
maxBytes : MAX_IMG_SIZE,
saveAs : function(__newFileStream, cb) {
Blueprint.create(req, res, function(err, newInstance) {
if (err) {
// This call breaks down the application
// This is the place where saving file should be canceled
cb(err);
} else {
// Image name will be image Id
cb(null, newInstance.id.toString());
}
});
}
},
function whenDone(err, uploadedFiles) {
if (err) {
res.negotiate(err);
} else {
res.ok();
}
});
saveAs 関数では、最初にレコードをデータベースに保存し、アップロードされたファイルを、保存されたレコードから返された id のような名前で保存します。しかし、データベースへの保存に失敗した場合 (たとえば、検証エラーが原因で)、ディスクへのファイルの保存をキャンセルして、そのエラーをさらに渡すにはどうすればよいですか?