728x90
반응형
CopySource에 복사 경로 + 원본 파일명만 적었는데 Bucket 이름까지 작성해야한다.
S3 예제 코드
const input = {
"Bucket": "destinationbucket",
"CopySource": "/sourcebucket/HappyFacejpg",
"Key": "HappyFaceCopyjpg"
};
const command = new CopyObjectCommand(input);
const response = await client.send(command);
작성 코드
const Bucket = process.env.AMPLIFY_BUCKET;
const s3 = new S3Client({
region: process.env.AWS_REGION,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
},
});
await s3.send(
new CopyObjectCommand({
Bucket: ,
CopySource: Bucket + '/' + originFileName,
Key: copyFileName,
}),
);
권한 - 버킷 정책
// BUCKET NAME, ACCOUNT ID 작성 요망
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::[BUCKET NAME]/*"
},
{
"Sid": "2",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::[ACCOUNT ID]:root"
},
"Action": [
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::[BUCKET NAME]/*"
}
]
}
이미지 업로드할 때 먼저 temp 폴더에 업로드 후 게시물 저장 로직에 temp 폴더에서 실제 저장소로 이미지를 복사 후 temp 폴더의 이미지를 제거했을 때 일어난 오류였다.
728x90
반응형
'NEXT' 카테고리의 다른 글
Only plain objects, and a few built-ins, can be passed to Server Actions. (0) | 2024.10.08 |
---|---|
NEXT JS + Google Analytics Connect Setting (0) | 2024.08.07 |
Parallel Routes Modal Difficult Error (0) | 2024.07.25 |
NextJs Next-auth getSession() 로그인 정보 확인 (0) | 2024.07.23 |
NEXT 14 NEXT-AUTH 5 middleware.ts not working (0) | 2024.07.11 |