임연수

change upload filename as it's own name

add gitignore upload folder
1 node_modules/ 1 node_modules/
2 .idea/ 2 .idea/
3 -package-lock.json
...\ No newline at end of file ...\ No newline at end of file
3 +package-lock.json
4 +/uploads
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -14,13 +14,13 @@ app.set('view engine', 'html'); ...@@ -14,13 +14,13 @@ app.set('view engine', 'html');
14 app.engine('html', require('ejs').renderFile); 14 app.engine('html', require('ejs').renderFile);
15 app.use(bodyParser.urlencoded({extended:false})); 15 app.use(bodyParser.urlencoded({extended:false}));
16 16
17 +var imgname;
17 var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다. 18 var storage = multer.diskStorage({ //이 객체의 프로퍼티는 2개갖고 있다.
18 destination: function (req, file, cb) { 19 destination: function (req, file, cb) {
19 cb(null, 'uploads/');//업로드 위치를 저장하는 path함수 20 cb(null, 'uploads/');//업로드 위치를 저장하는 path함수
20 }, 21 },
21 filename: function (req, file, cb) { 22 filename: function (req, file, cb) {
22 - // cb(null, file.originalname); //저장할 파일명 23 + cb(null, file.originalname);
23 - cb(null, 'mypic.jpg');
24 } 24 }
25 }); 25 });
26 var upload = multer({ storage: storage}); 26 var upload = multer({ storage: storage});
...@@ -31,7 +31,6 @@ var subscriptionKey = '61650f4a2941462ea2dba74eabefd114'; ...@@ -31,7 +31,6 @@ var subscriptionKey = '61650f4a2941462ea2dba74eabefd114';
31 // subscription keys. For example, if you got your subscription keys from 31 // subscription keys. For example, if you got your subscription keys from
32 // westus, replace "westcentralus" in the URL below with "westus". 32 // westus, replace "westcentralus" in the URL below with "westus".
33 var uriBase = 'https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect'; 33 var uriBase = 'https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect';
34 -var imageUrl = 'http://54.180.159.73/user/mypic.jpg';
35 // Request parameters. 34 // Request parameters.
36 var params = { 35 var params = {
37 'returnFaceId': 'true', 36 'returnFaceId': 'true',
...@@ -39,16 +38,6 @@ var params = { ...@@ -39,16 +38,6 @@ var params = {
39 'returnFaceAttributes': 'age,gender,emotion,hair' 38 'returnFaceAttributes': 'age,gender,emotion,hair'
40 //'headPose,smile,facialHair,glasses, emotion,hair,makeup,occlusion,accessories,blur,exposure,noise' 39 //'headPose,smile,facialHair,glasses, emotion,hair,makeup,occlusion,accessories,blur,exposure,noise'
41 }; 40 };
42 -var options = {
43 - uri: uriBase,
44 - qs: params,
45 - body: '{"url": ' + '"' + imageUrl + '"}',
46 - headers: {
47 - 'Content-Type': 'application/json',
48 - 'Ocp-Apim-Subscription-Key' : subscriptionKey
49 - }
50 -};
51 -
52 41
53 app.get('/home', function(req,res){ 42 app.get('/home', function(req,res){
54 console.log("home"); 43 console.log("home");
...@@ -57,10 +46,19 @@ app.get('/home', function(req,res){ ...@@ -57,10 +46,19 @@ app.get('/home', function(req,res){
57 46
58 app.post('/uploads', upload.single('userfile'),function(req,res){ 47 app.post('/uploads', upload.single('userfile'),function(req,res){
59 res.render("facedetection"); 48 res.render("facedetection");
60 - 49 + imgname = req.file.filename;
61 }); 50 });
62 app.get('/send2api', function (req, res) { 51 app.get('/send2api', function (req, res) {
63 - console.log("aa") 52 +
53 + var options = {
54 + uri: uriBase,
55 + qs: params,
56 + body: '{"url": "http://54.180.159.73:8080/uploads/' + imgname + '"}',
57 + headers: {
58 + 'Content-Type': 'application/json',
59 + 'Ocp-Apim-Subscription-Key' : subscriptionKey
60 + }
61 + };
64 request.post(options, (error, response, body) => { 62 request.post(options, (error, response, body) => {
65 if (error) { 63 if (error) {
66 console.log('Error: ', error); 64 console.log('Error: ', error);
...@@ -73,5 +71,5 @@ app.get('/send2api', function (req, res) { ...@@ -73,5 +71,5 @@ app.get('/send2api', function (req, res) {
73 }) 71 })
74 72
75 app.listen(8080,function(){ 73 app.listen(8080,function(){
76 - console.log("connect 8080"); 74 + console.log("connect 8080");
77 }); 75 });
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
20 </head> 20 </head>
21 <body ng-controller="mainAdminController"> 21 <body ng-controller="mainAdminController">
22 <div class="left-box"> 22 <div class="left-box">
23 - <img src="http://54.180.159.73:8080/user/mypic.jpg"> 23 + <img src="http://54.180.159.73:8080/uploads/mypic.jpg">
24 </div> 24 </div>
25 25
26 <div class="right-box"> 26 <div class="right-box">
......