Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
MAC_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
오윤석
2021-05-13 06:06:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
495ffa5874c35ddf1ef391efbf7d206a2659fd27
495ffa58
1 parent
3c2f6554
gif download
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
lambda/gif-download/index.js
lambda/gif-download/index.js
0 → 100644
View file @
495ffa5
const
aws
=
require
(
'aws-sdk'
);
const
s3
=
new
aws
.
S3
();
exports
.
handler
=
async
(
event
)
=>
{
if
(
!
event
[
'queryStringParameters'
]
||
!
event
[
'queryStringParameters'
][
'id'
])
{
return
{
statusCode
:
400
}
}
const
id
=
event
[
'queryStringParameters'
][
'id'
];
const
data
=
await
download
(
id
);
return
{
statusCode
:
200
,
headers
:{
"Content-Type"
:
"image/gif"
},
isBase64Encoded
:
true
,
body
:
data
.
Body
.
toString
(
"base64"
)
}
};
const
download
=
(
id
)
=>
{
const
bucket
=
'gif-generator'
;
const
path
=
`/gif/
${
id
}
.gif`
;
const
params
=
{
Bucket
:
bucket
,
Key
:
path
}
return
new
Promise
((
resolve
,
reject
)
=>
{
s3
.
getObject
(
params
,
(
err
,
data
)
=>
{
if
(
err
){
console
.
log
(
"download err"
);
console
.
log
(
err
);
reject
(
err
);
}
else
{
console
.
log
(
"download success"
);
console
.
log
(
data
);
resolve
(
data
);
}
});
});
}
\ No newline at end of file
Please
register
or
login
to post a comment