임연수

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 3 package-lock.json
...\ No newline at end of file ...\ No newline at end of file
4 -uploads/mypic.jpg
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,9 +2,24 @@ var express = require('express'); ...@@ -2,9 +2,24 @@ 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 +var vhost = 'nodejsapp.local';
7 +var port = process.env.PORT || 8080;
8 +var ip = process.env.IP || "localhost";
6 9
7 -var _storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다. 10 +
11 +var app= express();
12 +
13 +app.set('port', port);
14 +app.locals.pretty = true;
15 +app.engine('html', require('ejs').renderFile);
16 +app.use(express.static('public'));
17 +app.use('/user',express.static('uploads'));
18 +app.set('views','./views');
19 +app.set('view engine', 'html');
20 +app.use(bodyParser.urlencoded({extended:false}));
21 +
22 +var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다.
8 destination: function (req, file, cb) { 23 destination: function (req, file, cb) {
9 cb(null, 'uploads/');//업로드 위치를 저장하는 path함수 24 cb(null, 'uploads/');//업로드 위치를 저장하는 path함수
10 }, 25 },
...@@ -12,44 +27,53 @@ var _storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 ...@@ -12,44 +27,53 @@ var _storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고
12 // cb(null, file.originalname); //저장할 파일명 27 // cb(null, file.originalname); //저장할 파일명
13 cb(null, 'mypic.jpg'); 28 cb(null, 'mypic.jpg');
14 } 29 }
15 - }) 30 +});
16 - var upload = multer({ storage: _storage}) 31 +var upload = multer({ storage: storage});
17 -app.locals.pretty = true; 32 +
18 33
19 -app.engine('html', require('ejs').renderFile); 34 +
20 -app.use(express.static('public')); 35 +// Replace <Subscription Key> with your valid subscription key.
21 -app.use('/user',express.static('uploads')); 36 +var subscriptionKey = '61650f4a2941462ea2dba74eabefd114';
22 -app.set('views','./views'); 37 +// You must use the same location in your REST call as you used to get your
23 -app.set('view engine', 'html'); 38 +// subscription keys. For example, if you got your subscription keys from
24 -app.use(bodyParser.urlencoded({extended:false})); 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 +};
25 58
26 app.get('/home', function(req,res){ 59 app.get('/home', function(req,res){
27 console.log("home"); 60 console.log("home");
28 res.render('upload'); 61 res.render('upload');
29 }); 62 });
30 - 63 +app.post('/uploads', upload.single('userfile'),function(req,res){
31 -/*app.post('/uploads',upload.single('userfile'),function(req,res){ 64 + res.render("result")
32 - 65 + console.log(req.file.path)
33 - upload(req,res,function(err) { 66 + request.post(options, (error, response, body) => {
34 - if(err) { 67 + if (error) {
35 - return res.end("Error uploading file."); 68 + console.log('Error: ', error);
69 + return;
36 } 70 }
37 - res.end("File is uploaded"); 71 + let jsonResponse = JSON.stringify(JSON.parse(body), null, ' ');
72 + console.log('JSON Response\n');
73 + console.log(jsonResponse);
38 }); 74 });
39 - console.log(req.file);
40 - res.render('facedetection');
41 -
42 -})*/
43 -app.post('/uploads', upload.single('userfile'),function(req,res){
44 -
45 -
46 - console.log("uploads");
47 - console.log(req.file);
48 -
49 - res.render('facedetection');
50 -
51 }); 75 });
52 76
53 -app.listen(8080, function(){ 77 +var server = http.createServer(app).listen(app.get('port'), function () {
54 - console.log("connnected, 8080 port!"); 78 + console.log('Express server listening on port ' + vhost + ":" + server.address().port);
55 }); 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,51 +59,32 @@ ...@@ -64,51 +59,32 @@
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 -
73 <div class="wow fadeInUp section-title" data-wow-delay="0.2s"> 66 <div class="wow fadeInUp section-title" data-wow-delay="0.2s">
74 <!-- SECTION TITLE --> 67 <!-- SECTION TITLE -->
75 <h2>자, 이제 나이를 측정하고 싶은 사람의 사진을 <br/>업로드 해주세요!</h2> 68 <h2>자, 이제 나이를 측정하고 싶은 사람의 사진을 <br/>업로드 해주세요!</h2>
76 </div> 69 </div>
77 70
78 - 71 + <div>
79 -<div>
80 <ul class="actions"> 72 <ul class="actions">
81 <form action="/uploads" method="post" enctype="multipart/form-data"> 73 <form action="/uploads" method="post" enctype="multipart/form-data">
74 + <input type="file" name="userfile" class="upload" value="업로드">
82 <input type="submit" value="완료" class= "button"> 75 <input type="submit" value="완료" class= "button">
83 </form> 76 </form>
84 -<br>
85 - </ul>
86 -</div>
87 - <div id="wrapper">
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> 77 </ul>
98 </div> 78 </div>
99 </div> 79 </div>
100 - 80 + </div>
101 - 81 + </div>
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 -
112 <div class="wow fadeInUp col-md-12 col-sm-12" data-wow-delay="0.8s"> 88 <div class="wow fadeInUp col-md-12 col-sm-12" data-wow-delay="0.8s">
113 <p class="white-color"> Opensource software programming 2018 RETURN</p> 89 <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">
...@@ -116,19 +92,23 @@ ...@@ -116,19 +92,23 @@
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>
97 + <!--스페이스바 두 개 ^^7-->
121 <li><a href="#" onclick="javascript:window.open('https://twitter.com/intent/tweet?text=[%EA%B3%B5%EC%9C%A0]%20' 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>
102 + <!--스페이스바 두 개 ^^7-->
125 <li><a href="#" onclick="javascript:window.open('https://plus.google.com/share?url=' 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>
......