임연수

connect to api at app.js,

debug upload button upload.html
1 node_modules/ 1 node_modules/
2 .idea/ 2 .idea/
3 -package-lock.json
4 -uploads/mypic.jpg
...\ No newline at end of file ...\ No newline at end of file
3 +package-lock.json
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,20 +2,16 @@ var express = require('express'); ...@@ -2,20 +2,16 @@ var express = require('express');
2 var bodyParser= require('body-parser');//post할때 필요 2 var bodyParser= require('body-parser');//post할때 필요
3 var multer = require('multer'); //업로드할 때 필요 3 var multer = require('multer'); //업로드할 때 필요
4 var request = require('request'); 4 var request = require('request');
5 -var app=express(); 5 +var http = require('http');
6 - 6 +var vhost = 'nodejsapp.local';
7 -var _storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다. 7 +var port = process.env.PORT || 8080;
8 - destination: function (req, file, cb) { 8 +var ip = process.env.IP || "localhost";
9 - cb(null, 'uploads/');//업로드 위치를 저장하는 path함수 9 +
10 - },
11 - filename: function (req, file, cb) {
12 - // cb(null, file.originalname); //저장할 파일명
13 - cb(null, 'mypic.jpg');
14 - }
15 - })
16 - var upload = multer({ storage: _storage})
17 -app.locals.pretty = true;
18 10
11 +var app= express();
12 +
13 +app.set('port', port);
14 +app.locals.pretty = true;
19 app.engine('html', require('ejs').renderFile); 15 app.engine('html', require('ejs').renderFile);
20 app.use(express.static('public')); 16 app.use(express.static('public'));
21 app.use('/user',express.static('uploads')); 17 app.use('/user',express.static('uploads'));
...@@ -23,33 +19,61 @@ app.set('views','./views'); ...@@ -23,33 +19,61 @@ app.set('views','./views');
23 app.set('view engine', 'html'); 19 app.set('view engine', 'html');
24 app.use(bodyParser.urlencoded({extended:false})); 20 app.use(bodyParser.urlencoded({extended:false}));
25 21
26 -app.get('/home', function(req,res){ 22 +var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다.
27 - console.log("home"); 23 + destination: function (req, file, cb) {
28 - res.render('upload'); 24 + cb(null, 'uploads/');//업로드 위치를 저장하는 path함수
25 + },
26 + filename: function (req, file, cb) {
27 + // cb(null, file.originalname); //저장할 파일명
28 + cb(null, 'mypic.jpg');
29 + }
29 }); 30 });
31 +var upload = multer({ storage: storage});
30 32
31 -/*app.post('/uploads',upload.single('userfile'),function(req,res){
32 -
33 - upload(req,res,function(err) {
34 - if(err) {
35 - return res.end("Error uploading file.");
36 - }
37 - res.end("File is uploaded");
38 - });
39 - console.log(req.file);
40 - res.render('facedetection');
41 33
42 -})*/
43 -app.post('/uploads', upload.single('userfile'),function(req,res){
44 34
35 +// Replace <Subscription Key> with your valid subscription key.
36 +var subscriptionKey = '61650f4a2941462ea2dba74eabefd114';
37 +// You must use the same location in your REST call as you used to get your
38 +// subscription keys. For example, if you got your subscription keys from
39 +// westus, replace "westcentralus" in the URL below with "westus".
40 +var uriBase = 'https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect';
41 +var imageUrl = 'http://localhost:8080/user/mypic.jpg';
42 +// Request parameters.
43 +var params = {
44 + 'returnFaceId': 'true',
45 + 'returnFaceLandmarks': 'false',
46 + 'returnFaceAttributes': 'age,gender,emotion,hair'
47 + //'headPose,smile,facialHair,glasses, emotion,hair,makeup,occlusion,accessories,blur,exposure,noise'
48 +};
49 +var options = {
50 + uri: uriBase,
51 + qs: params,
52 + body: '{"url": ' + '"' + imageUrl + '"}',
53 + headers: {
54 + 'Content-Type': 'application/json',
55 + 'Ocp-Apim-Subscription-Key' : subscriptionKey
56 + }
57 +};
45 58
46 - console.log("uploads"); 59 +app.get('/home', function(req,res){
47 - console.log(req.file); 60 + console.log("home");
48 - 61 + res.render('upload');
49 - res.render('facedetection');
50 -
51 }); 62 });
52 - 63 +app.post('/uploads', upload.single('userfile'),function(req,res){
53 -app.listen(8080, function(){ 64 + res.render("result")
54 - console.log("connnected, 8080 port!"); 65 + console.log(req.file.path)
66 + request.post(options, (error, response, body) => {
67 + if (error) {
68 + console.log('Error: ', error);
69 + return;
70 + }
71 + let jsonResponse = JSON.stringify(JSON.parse(body), null, ' ');
72 + console.log('JSON Response\n');
73 + console.log(jsonResponse);
74 + });
55 }); 75 });
76 +
77 +var server = http.createServer(app).listen(app.get('port'), function () {
78 + console.log('Express server listening on port ' + vhost + ":" + server.address().port);
79 +});
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
18 18
19 <title>Age Detection</title> 19 <title>Age Detection</title>
20 20
21 -<link rel = "stylesheet" href="http://localhost:8080/assets/css/upload.css"> 21 +<link rel ="stylesheet" href="http://localhost:8080/assets/css/upload.css">
22 <link rel="stylesheet" href="http://localhost:8080/assets/css/bootstrap.min.css"> 22 <link rel="stylesheet" href="http://localhost:8080/assets/css/bootstrap.min.css">
23 <link rel="stylesheet" href="http://localhost:8080/assets/css/animate.css"> 23 <link rel="stylesheet" href="http://localhost:8080/assets/css/animate.css">
24 <link rel="stylesheet" href="http://localhost:8080/assets/css/magnific-popup.css"> 24 <link rel="stylesheet" href="http://localhost:8080/assets/css/magnific-popup.css">
...@@ -30,14 +30,10 @@ ...@@ -30,14 +30,10 @@
30 <script src="https://apis.google.com/js/platform.js" async defer> 30 <script src="https://apis.google.com/js/platform.js" async defer>
31 {lang: 'ko'} 31 {lang: 'ko'}
32 </script> 32 </script>
33 -
34 -
35 </head> 33 </head>
36 34
37 <body> 35 <body>
38 36
39 -
40 -
41 <!-- PRE LOADER --> 37 <!-- PRE LOADER -->
42 <div class="preloader"> 38 <div class="preloader">
43 <div class="spinner"> 39 <div class="spinner">
...@@ -45,7 +41,6 @@ ...@@ -45,7 +41,6 @@
45 </div> 41 </div>
46 </div> 42 </div>
47 43
48 -
49 <!-- HOME SECTION --> 44 <!-- HOME SECTION -->
50 <section id="home" class="parallax-section"> 45 <section id="home" class="parallax-section">
51 <div class="container"> 46 <div class="container">
...@@ -64,71 +59,56 @@ ...@@ -64,71 +59,56 @@
64 </div> 59 </div>
65 </section> 60 </section>
66 61
67 -
68 <!-- SERVICE SECTION --> 62 <!-- SERVICE SECTION -->
69 <section id="service" class="parallax-section"> 63 <section id="service" class="parallax-section">
70 - <div class="container"> 64 + <div class="container">
71 - <div class="row"> 65 + <div class="row">
72 - 66 + <div class="wow fadeInUp section-title" data-wow-delay="0.2s">
73 - <div class="wow fadeInUp section-title" data-wow-delay="0.2s"> 67 + <!-- SECTION TITLE -->
74 - <!-- SECTION TITLE --> 68 + <h2>자, 이제 나이를 측정하고 싶은 사람의 사진을 <br/>업로드 해주세요!</h2>
75 - <h2>자, 이제 나이를 측정하고 싶은 사람의 사진을 <br/>업로드 해주세요!</h2> 69 + </div>
76 - </div> 70 +
77 - 71 + <div>
78 - 72 + <ul class="actions">
79 -<div> 73 + <form action="/uploads" method="post" enctype="multipart/form-data">
80 - <ul class="actions"> 74 + <input type="file" name="userfile" class="upload" value="업로드">
81 - <form action="/uploads" method="post" enctype="multipart/form-data"> 75 + <input type="submit" value="완료" class= "button">
82 - <input type="submit" value="완료" class= "button"> 76 + </form>
83 - </form> 77 + </ul>
84 -<br> 78 + </div>
85 - </ul> 79 + </div>
86 -</div> 80 + </div>
87 - <div id="wrapper"> 81 + </div>
88 - <div class = "filebox">
89 - <br>
90 - <br>
91 - <br>
92 - <ul class="actions">
93 - <form action="/uploads" method="post" enctype="multipart/form-data">
94 - <label for="userfile">업로드</label>
95 - <input type="file" id="userfile" class="upload" value="업로드"></input>
96 - </form>
97 - </ul>
98 - </div>
99 - </div>
100 -
101 -
102 </section> 82 </section>
103 83
104 -
105 -
106 -
107 <!-- FOOTER SECTION --> 84 <!-- FOOTER SECTION -->
108 <footer> 85 <footer>
109 <div class="container"> 86 <div class="container">
110 <div class="row"> 87 <div class="row">
111 - 88 + <div class="wow fadeInUp col-md-12 col-sm-12" data-wow-delay="0.8s">
112 - <div class="wow fadeInUp col-md-12 col-sm-12" data-wow-delay="0.8s"> 89 + <p class="white-color"> Opensource software programming 2018 RETURN</p>
113 - <p class="white-color"> Opensource software programming 2018 RETURN</p>
114 <div class="wow fadeInUp" data-wow-delay="1s"> 90 <div class="wow fadeInUp" data-wow-delay="1s">
115 - <ul class="social-icon"> 91 + <ul class="social-icon">
116 - <li><a href="#" onclick="javascript:window.open('https://www.facebook.com/sharer/sharer.php?u=' 92 + <li><a href="#" onclick="javascript:window.open('https://www.facebook.com/sharer/sharer.php?u='
117 +encodeURIComponent(document.URL)+'&t='+encodeURIComponent(document.title), 'facebooksharedialog', 93 +encodeURIComponent(document.URL)+'&t='+encodeURIComponent(document.title), 'facebooksharedialog',
118 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" 94 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"
119 - alt="Share on Facebook" class = "fa fa-facebook"></a></li> 95 + alt="Share on Facebook" class = "fa fa-facebook"></a>
120 - &nbsp;&nbsp; <!--스페이스바 두 개 ^^7--> 96 + </li>
121 - <li><a href="#" onclick="javascript:window.open('https://twitter.com/intent/tweet?text=[%EA%B3%B5%EC%9C%A0]%20' 97 + <!--스페이스바 두 개 ^^7-->
98 + <li><a href="#" onclick="javascript:window.open('https://twitter.com/intent/tweet?text=[%EA%B3%B5%EC%9C%A0]%20'
122 +encodeURIComponent(document.URL)+'%20-%20'+encodeURIComponent(document.title), 'twittersharedialog', 99 +encodeURIComponent(document.URL)+'%20-%20'+encodeURIComponent(document.title), 'twittersharedialog',
123 - 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" alt="Share on Twitter" class="fa fa-twitter"></a></li> 100 + 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" alt="Share on Twitter" class="fa fa-twitter"></a>
124 - &nbsp;&nbsp; <!--스페이스바 두 개 ^^7--> 101 + </li>
125 - <li><a href="#" onclick="javascript:window.open('https://plus.google.com/share?url=' 102 + <!--스페이스바 두 개 ^^7-->
103 + <li><a href="#" onclick="javascript:window.open('https://plus.google.com/share?url='
126 +encodeURIComponent(document.URL), 'googleplussharedialog','menubar=no,toolbar=no,resizable=yes, scrollbars=yes,height=300,width=600');return false;" 104 +encodeURIComponent(document.URL), 'googleplussharedialog','menubar=no,toolbar=no,resizable=yes, scrollbars=yes,height=300,width=600');return false;"
127 - target="_blank" alt="Share on Google+" class="fa fa-google-plus"></a></li> 105 + target="_blank" alt="Share on Google+" class="fa fa-google-plus"></a>
106 + </li>
128 </ul> 107 </ul>
129 </div> 108 </div>
130 - </div> 109 + </div>
131 - </div> 110 + </div>
111 + </div>
132 </footer> 112 </footer>
133 113
134 <!-- SCRIPTS --> 114 <!-- SCRIPTS -->
...@@ -141,14 +121,12 @@ ...@@ -141,14 +121,12 @@
141 <script src="http://localhost:8080/assets/js/wow.min.js"></script> 121 <script src="http://localhost:8080/assets/js/wow.min.js"></script>
142 <script src="http://localhost:8080/assets/js/custom.js"></script> 122 <script src="http://localhost:8080/assets/js/custom.js"></script>
143 123
144 -<script> 124 +<script>/*
145 document.getElementById('userfile').onchange = function(){ 125 document.getElementById('userfile').onchange = function(){
146 alert(this.value+' Upload Ok!'); 126 alert(this.value+' Upload Ok!');
147 -} 127 +}*/
148 </script> 128 </script>
149 129
150 </body> 130 </body>
151 131
152 -</script>
153 -
154 </html> 132 </html>
......