daeun

modify cfr_test for data parsing

...@@ -3,6 +3,8 @@ var app = express(); ...@@ -3,6 +3,8 @@ var app = express();
3 var client_id = 'v3M4wjolGLkrvNA3GUIW'; 3 var client_id = 'v3M4wjolGLkrvNA3GUIW';
4 var client_secret = 'fKF6vjkWhE'; 4 var client_secret = 'fKF6vjkWhE';
5 var fs = require('fs'); 5 var fs = require('fs');
6 +//var bodyParser=require('body-parser');
7 +//app.use(bodyParser.json());
6 8
7 app.get('/', function (req, res) { 9 app.get('/', function (req, res) {
8 var request = require('request'); 10 var request = require('request');
...@@ -11,17 +13,26 @@ app.get('/', function (req, res) { ...@@ -11,17 +13,26 @@ app.get('/', function (req, res) {
11 13
12 var _formData = { 14 var _formData = {
13 image:'image', 15 image:'image',
14 - image: fs.createReadStream(__dirname + "\\IU.jpg") // FILE 이름 16 + image: fs.createReadStream(__dirname + "\\사진\\IU.jpg") // FILE 이름
15 }; 17 };
16 - var _req = request.post({url:api_url, formData:_formData, 18 + var _req = request.post(
17 - headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}}).on('response', function(response) { 19 + { url:api_url,
20 + formData:_formData,
21 + headers: {'X-Naver-Client-Id':client_id,
22 + 'X-Naver-Client-Secret': client_secret}
23 + }, (err,response,body) =>{
18 console.log(response.statusCode) // 200 24 console.log(response.statusCode) // 200
19 console.log(response.headers['content-type']) 25 console.log(response.headers['content-type'])
26 +
27 + data=JSON.parse(body);
28 + gender=data.faces[0].gender.value;
29 + emotion=data.faces[0].emotion.value
30 + console.log(emotion);
20 }); 31 });
21 - console.log( request.head ); 32 + console.log( request.head );
22 _req.pipe(res); // 브라우저로 출력 33 _req.pipe(res); // 브라우저로 출력
23 }); 34 });
24 35
25 app.listen(8080, function () { 36 app.listen(8080, function () {
26 - console.log('http://127.0.0.1:8080/face app listening on port 8080!'); 37 + console.log('http://127.0.0.1:8080 app listening on port 8080!');
27 }); 38 });
...\ No newline at end of file ...\ No newline at end of file
......