-1
私は現在、アップロード後のAPIを作成するためにnode.jsを使用しています。画像をアップロードするには、Watson Visual Recognition Serviceが処理します。これは現在、コンソールに記録されているJSONを返します。 処理が完了した後、このJSONをユーザーに送り返す方法はありますか? 私はNode.jsの初心者です。本当にありがとうございます。ノードJS API:サービス終了後、JSONをユーザーに返します。
これは私のコードです:
// initialising ...
app.post('/detectFaces', avatarUpload, (req, res) => {
avatarUpload(req, res, (err) => {
if (err || !req.file)
return res.send({ error: 'invalid_file' })
console.log(req.file);
var path = req.file.path;
var name = req.file.filename;
var params = {
images_file: fs.createReadStream(path)
};
//Call to the visual recognition Service
visual_recognition.detectFaces(params, function(err, res){
if(err)
console.log(err);
else
console.log(JSON.stringify(res, null, 2));
});
//The JSON of the visual Rec Service should send here.
res.send({ 'status' : 'check', url: 'uploads' + '/' + filename })
})
var params = {
images_file: fs.createReadStream(path)
};
});
app.listen(3000, function() {
console.log('Upload Server listening on port 3000');
});
を使用することができます。 *あなたが何をしたのか、*なぜ*を説明するか。 (また、最初のバージョンのように不完全な回答を投稿してから、編集して完成させてください。[この場合、忍者の編集です。]完全な回答を書いてください。) –
ありがとうございました:) – Jeet
ご返信ありがとうございます!この変更により、「送信後にヘッダーを送信できません」というエラーが表示されます。関数がビジュアルサービスの応答を待つようにする方法はありますか? – JSt