0
私はマルチフォームのマルチアップロードフォームを持っています。その後、Cloud Vision APIでイメージを処理し、OCR結果にいくつかの処理を行い、 next2)すべてのファイルが処理された後。Nodejsは、別のルートにリダイレクトするために非同期foreachコールバックを表現します
私はasync.forEachと私のコードを編集したが、私は私が間違って得たもの
TypeError: Cannot read property '0' of undefined
を得ましたか。
app.post('/vision/upload', upload.array("photos", 10), function(req, res) {
async.forEach(req.files, function (file, cb) {
var post = {url: file.location};
connection.query('SET FOREIGN_KEY_CHECKS=0;', function (err) {
if (err) throw err;
});
connection.query('SELECT * FROM documents WHERE documents.url = ?', file.location, function (err, res54) {
var o2 = isEmpty(res54);
var m9 = {};
if (o2) {
connection.query('INSERT INTO documents SET ?', post, function (err, res5) {
if (err) throw err;
DocumentsNextPage.push(res5.insertId);
});
} else {
connection.query('SELECT * FROM documents WHERE documents.url = ?', file.location, function (err, res9) {
m9 = res9;
});
connection.query('UPDATE documents SET ? WHERE ?', [{url: file.location}, {url: file.location}], function (err) {
if (err) throw err;
DocumentsNextPage.push(m9[0].id);
});
}
if (err) throw err;
});
const req2 = new vision.Request({
image: new vision.Image({
url: file.location
}),
features: [
new vision.Feature('DOCUMENT_TEXT_DETECTION', 10),
]
});
DocumentsNextPage.length = 0;
vision.annotate(req2).then((res2) => {
p1 = JSON.stringify(res2.responses);
p1up = p1.toUpperCase();
x7 = res2.responses[0].textAnnotations;
console.log(x7);
})
occurrencesText = new Occurrences(p1up, {ignored: arrayIgnoredWords});
var tt1 = occurrencesText.getSorted();
var oc1 = toArray(tt1);
var oc2 = unique(oc1);
for (var i = 0; i < 10; i++) {
occurencesResults.push(oc2[i][0]);
var postOccu = {name: oc2[i][0], active: 0, isOccurenceMeta: 1, url: file.location};
connection.query('REPLACE INTO metas SET ?', postOccu, function (err) {
if (err) throw err;
});
}
connection.query(queryString, function (err, rows, fields) {
if (err) throw err;
for (var i in rows) {
var fuse = new Fuse(x7, options);
var result = fuse.search(rows[i].name);
var t1 = isEmpty(result);
if (t1) {
} else {
arrayResults.push(rows[i].name);
var posTag0 = {name: [rows[i].name], active: 0, isOccurenceMeta: 0, url: file.location};
connection.query('INSERT INTO metas SET ?', posTag0, function (err) {
if (err) throw err;
});
}
}
connection.query('SELECT * FROM documents INNER JOIN metas ON documents.url = metas.url WHERE metas.url = ? GROUP BY metas.name ORDER BY documents.url DESC', file.location, function (err, res99) {
if (err) throw err;
for (var i in res99) {
if (res99[i].id != undefined) {
resultMetasDocs[i] = {'documents_id': res99[i].id, 'metas_id': res99[i].id_meta};
}
}
});
for (var i in resultMetasDocs) {
var documentHasMetas = resultMetasDocs[i];
connection.query('REPLACE INTO documents_has_metas SET ?', documentHasMetas, function (err) {
if (err) throw err;
});
}
})
})
cb();
}, function() {
res.redirect('/next2');
});
ありがとうございます!私はまだ同じエラーがありますTypeError: '/Users/florian/Downloads/multer-master/app.js:144:42の の未定義のプロパティ '0'を読むことができません /Users/florian/Downloads/multer-master/144:42は、for(var i = 0; i <10; i ++){ occurencesResults.push(oc2 [i] [0] ); var postOccu = {name:oc2 [i] [0]、アクティブ:0、isOccurenceMeta:1、url:file.location}; connection.query( '置き換えメタセット?'、postOccu、function(err){ if(err)throw err; }); } ' –