Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# production
/build
.env

# misc
.DS_Store
Expand All @@ -24,4 +25,4 @@ yarn-error.log*

# IDE
/.vscode
.eslintcache
.eslintcache
49 changes: 49 additions & 0 deletions src/api/aws/aws-s3.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<input type="file" onChange={handleFileInput} />
<img src="https://osds-bucket.s3.ap-northeast-2.amazonaws.com/image/undefined.png" />
</>
);
}

export default Profile;