Showing
5 changed files
with
33 additions
and
11 deletions
... | @@ -3,10 +3,12 @@ var express = require('express'); | ... | @@ -3,10 +3,12 @@ var express = require('express'); |
3 | var path = require('path'); | 3 | var path = require('path'); |
4 | var cookieParser = require('cookie-parser'); | 4 | var cookieParser = require('cookie-parser'); |
5 | var logger = require('morgan'); | 5 | var logger = require('morgan'); |
6 | +var fs = require('fs') | ||
6 | var AWS = require('aws-sdk'); | 7 | var AWS = require('aws-sdk'); |
7 | 8 | ||
9 | + | ||
8 | // 이미지를 저장할 버킷 이름 | 10 | // 이미지를 저장할 버킷 이름 |
9 | -var bucketName = "kindofyourdog"; | 11 | +var bucketName = "kindofyourdogimage"; |
10 | // s3 버킷의 엔드 포인트 | 12 | // s3 버킷의 엔드 포인트 |
11 | var bucketRegion = "ap-northeast-2"; | 13 | var bucketRegion = "ap-northeast-2"; |
12 | // AWS Cognito 인증 | 14 | // AWS Cognito 인증 |
... | @@ -21,11 +23,27 @@ AWS.config.update({ | ... | @@ -21,11 +23,27 @@ AWS.config.update({ |
21 | }) | 23 | }) |
22 | 24 | ||
23 | // 내가 사용할 S3 | 25 | // 내가 사용할 S3 |
24 | -var s3 = new aws.S3({ | 26 | +var s3 = new AWS.S3({ |
25 | apiVersion: "2006-03-01", | 27 | apiVersion: "2006-03-01", |
26 | params: {Bucket: bucketName} | 28 | params: {Bucket: bucketName} |
27 | }); | 29 | }); |
28 | 30 | ||
31 | +// 파일 업로드 | ||
32 | +const uploadFile = (fileName) => { | ||
33 | + const fileContent = fs.readFileSync(fileName); | ||
34 | + const params = { | ||
35 | + Bucket: bucketName, | ||
36 | + Key: fileName, // File name you want to save as in S3 | ||
37 | + Body: fileContent } | ||
38 | +; | ||
39 | + s3.upload(params, function(err, data) { | ||
40 | + if (err) { throw err; } | ||
41 | + console.log(`File uploaded successfully. ${data.Location}`); | ||
42 | + }); | ||
43 | +}; | ||
44 | +uploadFile('public/image/puppy.jpg'); | ||
45 | + | ||
46 | + | ||
29 | var indexRouter = require('./routes/index'); | 47 | var indexRouter = require('./routes/index'); |
30 | var usersRouter = require('./routes/users'); | 48 | var usersRouter = require('./routes/users'); |
31 | // image업로드 시 해당 route기능 사용 | 49 | // image업로드 시 해당 route기능 사용 | ... | ... |
public/image/puppy.jpg
0 → 100644
29.7 KB
... | @@ -6,8 +6,4 @@ router.get('/', function(req, res, next) { | ... | @@ -6,8 +6,4 @@ router.get('/', function(req, res, next) { |
6 | res.render('index', { title: 'KindOfYourDog' }); | 6 | res.render('index', { title: 'KindOfYourDog' }); |
7 | }); | 7 | }); |
8 | 8 | ||
9 | -router.post('/upload', function(req, res, next) { | ||
10 | - var name = "" | ||
11 | -}) | ||
12 | - | ||
13 | module.exports = router; | 9 | module.exports = router; | ... | ... |
... | @@ -6,4 +6,4 @@ router.get('/', function(req, res, next) { | ... | @@ -6,4 +6,4 @@ router.get('/', function(req, res, next) { |
6 | res.send('respond with a resource'); | 6 | res.send('respond with a resource'); |
7 | }); | 7 | }); |
8 | 8 | ||
9 | -module.exports = router; | 9 | +module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
2 | <html> | 2 | <html> |
3 | <head> | 3 | <head> |
4 | - <title><%= title %></title> | 4 | + <!-- **DO THIS**: --> |
5 | - <link rel='stylesheet' href='/stylesheets/style.css' /> | 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> | ||
7 | + <script src="./app.js"></script> | ||
8 | + <script> | ||
9 | + function getHtml(template) { | ||
10 | + return template.join('\n'); | ||
11 | + } | ||
12 | + listAlbums(); | ||
13 | + </script> | ||
6 | </head> | 14 | </head> |
7 | <body> | 15 | <body> |
8 | <h1><%= title %></h1> | 16 | <h1><%= title %></h1> |
9 | - <p>Welcome to <%= title %></p> | 17 | + <div id="app"></div> |
10 | </body> | 18 | </body> |
11 | -</html> | 19 | +</html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment