Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김현기
/
KindOfYourDog
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김현기
2020-06-13 06:19:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c293a0b69e122874c28afe4039596b25c2dccf32
c293a0b6
1 parent
6b2b79ed
파일 S3로 업로드 테스트완료
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
11 deletions
app.js
public/image/puppy.jpg
routes/index.js
routes/users.js
views/index.ejs
app.js
View file @
c293a0b
...
...
@@ -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
=
"kindofyourdog
image
"
;
// 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기능 사용
...
...
public/image/puppy.jpg
0 → 100644
View file @
c293a0b
29.7 KB
routes/index.js
View file @
c293a0b
...
...
@@ -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
;
...
...
routes/users.js
View file @
c293a0b
...
...
@@ -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
...
...
views/index.ejs
View file @
c293a0b
<!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
...
...
Please
register
or
login
to post a comment