Skip to content

Commit

Permalink
S3 region 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
odumag99 committed Jan 19, 2025
1 parent 78f63a3 commit 79a1b3c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions snuvote/app/vote/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import secrets
import os
import boto3
from botocore.config import Config


ALLOWED_EXTENSIONS = {"jpg", "jpeg", "png", "gif"}
Expand All @@ -23,7 +24,7 @@ def upload_vote_images(self, vote: Vote, images: List[UploadFile]) -> None:
# voteimage를 저장하고 DB에 정보를 저장하는 함수

# S3 client 생성
s3 = boto3.client('s3', aws_access_key_id=os.getenv('AWS_S3_ACCESS_KEY_ID'), aws_secret_access_key=os.getenv('AWS_S3_SECRET_ACCESS_KEY'))
s3 = boto3.client('s3', aws_access_key_id=os.getenv('AWS_S3_ACCESS_KEY_ID'), aws_secret_access_key=os.getenv('AWS_S3_SECRET_ACCESS_KEY'), config=Config(region_name=os.getenv('AWS_DEFAULT_REGION')))

image_order = 0 # VoteImage.order에 저장될 이미지 순서 번호

Expand All @@ -36,7 +37,7 @@ def upload_vote_images(self, vote: Vote, images: List[UploadFile]) -> None:
s3.upload_fileobj(image.file, os.getenv('AWS_S3_BUCKET_NAME'), image_path)

# S3 버킷에 업로드된 이미지 경로
image_src = f'https://{os.getenv("AWS_S3_BUCKET_NAME")}.s3.ap-northeast-2.amazonaws.com/{image_path}'
image_src = f'https://{os.getenv("AWS_S3_BUCKET_NAME")}.s3.{os.getenv("AWS_DEFAULT_REGION")}.amazonaws.com/{image_path}'

# VoteImage 테이블에 이미지 정보 저장
self.vote_store.add_vote_image(vote_id=vote.id, image_order=image_order, image_src=image_src)
Expand Down

0 comments on commit 79a1b3c

Please sign in to comment.