Showing
3 changed files
with
31 additions
and
24 deletions
... | @@ -3,9 +3,33 @@ var express = require('express'); | ... | @@ -3,9 +3,33 @@ 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 AWS = require('aws-sdk'); | ||
7 | + | ||
8 | +// 이미지를 저장할 버킷 이름 | ||
9 | +var bucketName = "kindofyourdog"; | ||
10 | +// s3 버킷의 엔드 포인트 | ||
11 | +var bucketRegion = "ap-northeast-2"; | ||
12 | +// AWS Cognito 인증 | ||
13 | +var IdentityPoolId = "ap-northeast-2:7cba9a17-588b-40d6-8c70-eb8ba4d573be"; | ||
14 | + | ||
15 | +// AWS의 config 정보를 Update해준다 -> 이용자가 S3 버킷에 접근 가능하다 | ||
16 | +AWS.config.update({ | ||
17 | + region:bucketRegion, | ||
18 | + credentials:new AWS.CognitoIdentityCredentials({ | ||
19 | + IdentityPoolId:IdentityPoolId | ||
20 | + }) | ||
21 | +}) | ||
22 | + | ||
23 | +// 내가 사용할 S3 | ||
24 | +var s3 = new aws.S3({ | ||
25 | + apiVersion: "2006-03-01", | ||
26 | + params: {Bucket: bucketName} | ||
27 | +}); | ||
6 | 28 | ||
7 | var indexRouter = require('./routes/index'); | 29 | var indexRouter = require('./routes/index'); |
8 | var usersRouter = require('./routes/users'); | 30 | var usersRouter = require('./routes/users'); |
31 | +// image업로드 시 해당 route기능 사용 | ||
32 | +var imageUploadRouter = require('./routes/imageUpload'); | ||
9 | 33 | ||
10 | var app = express(); | 34 | var app = express(); |
11 | 35 | ||
... | @@ -21,6 +45,8 @@ app.use(express.static(path.join(__dirname, 'public'))); | ... | @@ -21,6 +45,8 @@ app.use(express.static(path.join(__dirname, 'public'))); |
21 | 45 | ||
22 | app.use('/', indexRouter); | 46 | app.use('/', indexRouter); |
23 | app.use('/users', usersRouter); | 47 | app.use('/users', usersRouter); |
48 | +//이미지 업로드 | ||
49 | +app.use('/upload', imageUploadRouter); | ||
24 | 50 | ||
25 | // catch 404 and forward to error handler | 51 | // catch 404 and forward to error handler |
26 | app.use(function(req, res, next) { | 52 | app.use(function(req, res, next) { | ... | ... |
createBucket.js
deleted
100644 → 0
1 | -const AWS = require('aws-sdk'); | ||
2 | -const ID = 'id'; | ||
3 | -const SECRET = 'secret'; | ||
4 | - | ||
5 | -const BUCKET_NAME = 'dogpicture-dizzi'; | ||
6 | - | ||
7 | -const s3 = new AWS.S3 ({ | ||
8 | - accessKeyId: ID, | ||
9 | - secretAccessKey:SECRET | ||
10 | -}); | ||
11 | - | ||
12 | -const params = { | ||
13 | - Bucket: BUCKET_NAME, | ||
14 | - CreateBucketConfiguration: { | ||
15 | - //Set your regieon here | ||
16 | - LocationConstraint : "us-east-1" | ||
17 | - } | ||
18 | -}; | ||
19 | - | ||
20 | -s3.createBucket(params, function(err, data) { | ||
21 | - if (err) console.log(err, err.stack); | ||
22 | - else console.log('Bucket Created Successfully', data.Location); | ||
23 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -3,7 +3,11 @@ var router = express.Router(); | ... | @@ -3,7 +3,11 @@ var router = express.Router(); |
3 | 3 | ||
4 | /* GET home page. */ | 4 | /* GET home page. */ |
5 | router.get('/', function(req, res, next) { | 5 | router.get('/', function(req, res, next) { |
6 | - res.render('index', { title: 'Express' }); | 6 | + res.render('index', { title: 'KindOfYourDog' }); |
7 | }); | 7 | }); |
8 | 8 | ||
9 | +router.post('/upload', function(req, res, next) { | ||
10 | + var name = "" | ||
11 | +}) | ||
12 | + | ||
9 | module.exports = router; | 13 | module.exports = router; | ... | ... |
-
Please register or login to post a comment