Skip to content

Commit

Permalink
feat: 프로필 이미지 업로드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
wonyangs committed Sep 9, 2024
1 parent 7d3b11e commit d7e7a35
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import shutil
import os
from app.dependencies.token_validation import validate_token
from app.services.s3_upload import get_presigned_url, upload_to_s3
from app.services.s3_upload import get_presigned_url, upload_to_s3, image_get_presigned_url
from app.services.transcode import trigger_transcode_job
from app.core.config import settings

router = APIRouter()

Expand Down Expand Up @@ -32,6 +33,26 @@ async def upload_video(
"transcode_job": transcode_job_data
}


@router.post("/profiles/")
async def update_member(
file: UploadFile = File(...), # 이미지 파일 업로드
):
# Step 1: Get S3 presigned URL from external API for the image upload
presigned_url_data = image_get_presigned_url()
presigned_url = presigned_url_data["upload_url"]
s3_filename = presigned_url_data["file_name"]

# Step 2: Upload image to S3 using presigned URL
file.file.seek(0)
upload_to_s3(presigned_url, file.file)

return {
"message": "Member updated successfully",
"profileImageUrl": f"{ settings.cdn_domain }/{ s3_filename }"
}


@router.get("/")
async def healthcheck():
return {"status": "healthy"}
2 changes: 2 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ class Settings(BaseSettings):
api_base_url: str
token_validation_url: str
s3_presigned_url: str
image_s3_presigned_url: str
transcode_url: str
environment: str = "dev"
aws_api_base_url: str
cdn_domain: str

class Config:
env_file = "env.list"
Expand Down
16 changes: 16 additions & 0 deletions app/services/s3_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
from fastapi import HTTPException
from app.core.config import settings

def image_get_presigned_url():
print(f"S3 Presigned URL: {settings.s3_presigned_url}")
full_url = f"{settings.aws_api_base_url}{settings.image_s3_presigned_url}"
print(f"Requesting URL: {full_url}")

presigned_url_response = requests.get(
full_url
)

print(presigned_url_response.json())

if presigned_url_response.status_code != 200:
raise HTTPException(status_code=500, detail="Failed to obtain presigned URL")

return presigned_url_response.json()

def get_presigned_url():
print(f"S3 Presigned URL: {settings.s3_presigned_url}")
full_url = f"{settings.aws_api_base_url}{settings.s3_presigned_url}"
Expand Down
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
annotated-types==0.7.0
anyio==4.4.0
awsebcli==3.20.10
blessed==1.20.0
botocore==1.31.85
cement==2.8.2
certifi==2024.7.4
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.3
exceptiongroup==1.2.2
fastapi==0.112.0
h11==0.14.0
httpcore==1.0.5
httpx==0.27.2
idna==3.7
jmespath==1.0.1
pathspec==0.10.1
pydantic==2.8.2
pydantic-settings==2.4.0
pydantic_core==2.20.1
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-multipart==0.0.9
PyYAML==6.0.2
requests==2.32.3
semantic-version==2.8.5
six==1.16.0
sniffio==1.3.1
starlette==0.37.2
termcolor==1.1.0
typing_extensions==4.12.2
urllib3==2.2.2
uvicorn==0.30.6
wcwidth==0.1.9

0 comments on commit d7e7a35

Please sign in to comment.