Showing
2 changed files
with
50 additions
and
8 deletions
... | @@ -12,13 +12,13 @@ var bucketName = "kindofyourdogimage"; | ... | @@ -12,13 +12,13 @@ var bucketName = "kindofyourdogimage"; |
12 | // s3 버킷의 엔드 포인트 | 12 | // s3 버킷의 엔드 포인트 |
13 | var bucketRegion = "ap-northeast-2"; | 13 | var bucketRegion = "ap-northeast-2"; |
14 | // AWS Cognito 인증 | 14 | // AWS Cognito 인증 |
15 | -var IdentityPoolId = "ap-northeast-2:7cba9a17-588b-40d6-8c70-eb8ba4d573be"; | 15 | +var identityPoolId = "ap-northeast-2:7cba9a17-588b-40d6-8c70-eb8ba4d573be"; |
16 | 16 | ||
17 | // AWS의 config 정보를 Update해준다 -> 이용자가 S3 버킷에 접근 가능하다 | 17 | // AWS의 config 정보를 Update해준다 -> 이용자가 S3 버킷에 접근 가능하다 |
18 | AWS.config.update({ | 18 | AWS.config.update({ |
19 | region:bucketRegion, | 19 | region:bucketRegion, |
20 | credentials:new AWS.CognitoIdentityCredentials({ | 20 | credentials:new AWS.CognitoIdentityCredentials({ |
21 | - IdentityPoolId:IdentityPoolId | 21 | + IdentityPoolId:identityPoolId |
22 | }) | 22 | }) |
23 | }) | 23 | }) |
24 | 24 | ||
... | @@ -28,6 +28,8 @@ var s3 = new AWS.S3({ | ... | @@ -28,6 +28,8 @@ var s3 = new AWS.S3({ |
28 | params: {Bucket: bucketName} | 28 | params: {Bucket: bucketName} |
29 | }); | 29 | }); |
30 | 30 | ||
31 | +const fileName = 'puppy.jpg'; | ||
32 | + | ||
31 | // 파일 업로드 | 33 | // 파일 업로드 |
32 | const uploadFile = (fileName) => { | 34 | const uploadFile = (fileName) => { |
33 | const fileContent = fs.readFileSync(fileName); | 35 | const fileContent = fs.readFileSync(fileName); |
... | @@ -41,13 +43,55 @@ const uploadFile = (fileName) => { | ... | @@ -41,13 +43,55 @@ const uploadFile = (fileName) => { |
41 | console.log(`File uploaded successfully. ${data.Location}`); | 43 | console.log(`File uploaded successfully. ${data.Location}`); |
42 | }); | 44 | }); |
43 | }; | 45 | }; |
44 | -uploadFile('public/image/puppy.jpg'); | 46 | +uploadFile(fileName); |
47 | + | ||
48 | +// rekognition 객체 | ||
49 | +const client = new AWS.Rekognition(); | ||
50 | + | ||
51 | +const params = { | ||
52 | + "Image": { | ||
53 | + "S3Object": { | ||
54 | + "Bucket": bucketName, | ||
55 | + "Name": fileName | ||
56 | + } | ||
57 | + }, | ||
58 | + "MaxLabels": 10, | ||
59 | + "MinConfidence": 75 | ||
60 | +} | ||
61 | + | ||
62 | +// 이미지 분석하기 | ||
63 | +client.detectLabels(params, function(err, response) { | ||
64 | + if (err) { | ||
65 | + console.log(err, err.stack); // an error occurred | ||
66 | + } else { | ||
67 | + console.log(`Detected labels for: ${photo}`) | ||
68 | + response.Labels.forEach(label => { | ||
69 | + console.log(`Label: ${label.Name}`) | ||
70 | + console.log(`Confidence: ${label.Confidence}`) | ||
71 | + console.log("Instances:") | ||
72 | + label.Instances.forEach(instance => { | ||
73 | + let box = instance.BoundingBox | ||
74 | + console.log(" Bounding box:") | ||
75 | + console.log(` Top: ${box.Top}`) | ||
76 | + console.log(` Left: ${box.Left}`) | ||
77 | + console.log(` Width: ${box.Width}`) | ||
78 | + console.log(` Height: ${box.Height}`) | ||
79 | + console.log(` Confidence: ${instance.Confidence}`) | ||
80 | + }) | ||
81 | + console.log("Parents:") | ||
82 | + label.Parents.forEach(parent => { | ||
83 | + console.log(` ${parent.Name}`) | ||
84 | + }) | ||
85 | + console.log("------------") | ||
86 | + console.log("") | ||
87 | + }) // for response.labels | ||
88 | + } // if | ||
89 | +}); | ||
45 | 90 | ||
46 | 91 | ||
47 | var indexRouter = require('./routes/index'); | 92 | var indexRouter = require('./routes/index'); |
48 | var usersRouter = require('./routes/users'); | 93 | var usersRouter = require('./routes/users'); |
49 | // image업로드 시 해당 route기능 사용 | 94 | // image업로드 시 해당 route기능 사용 |
50 | -var imageUploadRouter = require('./routes/imageUpload'); | ||
51 | 95 | ||
52 | var app = express(); | 96 | var app = express(); |
53 | 97 | ||
... | @@ -63,8 +107,6 @@ app.use(express.static(path.join(__dirname, 'public'))); | ... | @@ -63,8 +107,6 @@ app.use(express.static(path.join(__dirname, 'public'))); |
63 | 107 | ||
64 | app.use('/', indexRouter); | 108 | app.use('/', indexRouter); |
65 | app.use('/users', usersRouter); | 109 | app.use('/users', usersRouter); |
66 | -//이미지 업로드 | ||
67 | -app.use('/upload', imageUploadRouter); | ||
68 | 110 | ||
69 | // catch 404 and forward to error handler | 111 | // catch 404 and forward to error handler |
70 | app.use(function(req, res, next) { | 112 | app.use(function(req, res, next) { | ... | ... |
... | @@ -3,7 +3,7 @@ | ... | @@ -3,7 +3,7 @@ |
3 | <head> | 3 | <head> |
4 | <!-- **DO THIS**: --> | 4 | <!-- **DO THIS**: --> |
5 | <!-- Replace SDK_VERSION_NUMBER with the current SDK version number --> | 5 | <!-- Replace SDK_VERSION_NUMBER with the current SDK version number --> |
6 | - <script src="https://sdk.amazonaws.com/js/aws-sdk-2.283.1.min.js"></script> | 6 | + <script src="https://sdk.amazonaws.com/js/aws-sdk-SDK_VERSION_NUMBER.js"></script> |
7 | <script src="./app.js"></script> | 7 | <script src="./app.js"></script> |
8 | <script> | 8 | <script> |
9 | function getHtml(template) { | 9 | function getHtml(template) { |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | </script> | 13 | </script> |
14 | </head> | 14 | </head> |
15 | <body> | 15 | <body> |
16 | - <h1><%= title %></h1> | 16 | + <h1>My Photo Albums App</h1> |
17 | <div id="app"></div> | 17 | <div id="app"></div> |
18 | </body> | 18 | </body> |
19 | </html> | 19 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment