From 3eea4d755fe387f34af9a4da597f99d76b6ff628 Mon Sep 17 00:00:00 2001 From: euije Date: Wed, 10 Aug 2022 03:03:34 +0900 Subject: [PATCH 1/2] docs: Add AWS-S3 configuration --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dfb7adc..bcbdff6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # production /build +.env # misc .DS_Store @@ -24,4 +25,4 @@ yarn-error.log* # IDE /.vscode -.eslintcache \ No newline at end of file +.eslintcache From f9ddda5747bbbece77994c157cc1ec87b4c19e37 Mon Sep 17 00:00:00 2001 From: euije Date: Wed, 10 Aug 2022 03:05:02 +0900 Subject: [PATCH 2/2] test: Add AWS-S3 api test file upload --- src/api/aws/aws-s3.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/api/aws/aws-s3.js diff --git a/src/api/aws/aws-s3.js b/src/api/aws/aws-s3.js new file mode 100644 index 0000000..2c3cdea --- /dev/null +++ b/src/api/aws/aws-s3.js @@ -0,0 +1,49 @@ +import { useState } from "react"; +import AWS from "aws-sdk"; + +function Profile() { + const [ownerData, setOwnerData] = useState("너영나영노영누영2"); + const region = "ap-northeast-2"; + const bucket = "osds-bucket"; + const endpoint = "image/"; + + AWS.config.update({ + region: region, + accessKeyId: process.env.REACT_APP_AWS_ACCESS_KEY_ID, + secretAccessKey: process.env.REACT_APP_AWS_SECRET_ACCESS_KEY, + }); + + const handleFileInput = async (e) => { + const file = e.target.files[0]; + + const upload = new AWS.S3.ManagedUpload({ + params: { + Bucket: bucket, // 버킷 이름 + Key: endpoint + ownerData + ".png", // 유저 아이디 + Body: file, // 파일 객체 + }, + }); + console.log(process.env.REACT_APP_AWS_ACCESS_KEY_ID); + console.log(process.env.REACT_APP_AWS_SECRET_ACCESS_KEY); + + const promise = upload.promise(); + promise.then( + function () { + alert("성공"); + }, + function (err) { + alert("실패"); + console.log(err); + } + ); + }; + + return ( + <> + + + + ); +} + +export default Profile;