김현기

파일 S3로 업로드 테스트완료

......@@ -3,10 +3,12 @@ var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var fs = require('fs')
var AWS = require('aws-sdk');
// 이미지를 저장할 버킷 이름
var bucketName = "kindofyourdog";
var bucketName = "kindofyourdogimage";
// s3 버킷의 엔드 포인트
var bucketRegion = "ap-northeast-2";
// AWS Cognito 인증
......@@ -21,11 +23,27 @@ AWS.config.update({
})
// 내가 사용할 S3
var s3 = new aws.S3({
var s3 = new AWS.S3({
apiVersion: "2006-03-01",
params: {Bucket: bucketName}
});
// 파일 업로드
const uploadFile = (fileName) => {
const fileContent = fs.readFileSync(fileName);
const params = {
Bucket: bucketName,
Key: fileName, // File name you want to save as in S3
Body: fileContent }
;
s3.upload(params, function(err, data) {
if (err) { throw err; }
console.log(`File uploaded successfully. ${data.Location}`);
});
};
uploadFile('public/image/puppy.jpg');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
// image업로드 시 해당 route기능 사용
......
......@@ -6,8 +6,4 @@ router.get('/', function(req, res, next) {
res.render('index', { title: 'KindOfYourDog' });
});
router.post('/upload', function(req, res, next) {
var name = ""
})
module.exports = router;
......
......@@ -6,4 +6,4 @@ router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;
module.exports = router;
\ No newline at end of file
......
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<!-- **DO THIS**: -->
<!-- Replace SDK_VERSION_NUMBER with the current SDK version number -->
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.283.1.min.js"></script>
<script src="./app.js"></script>
<script>
function getHtml(template) {
return template.join('\n');
}
listAlbums();
</script>
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
<div id="app"></div>
</body>
</html>
</html>
\ No newline at end of file
......