Skip to content

Commit

Permalink
Fix: 이미지 처리 함수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
KangJeongHo1 committed Jun 17, 2024
1 parent 7ffe705 commit ffa109a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/common/utils/image_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from config.settings import MEDIA_URL
def get_image_uri(image_uri):
if image_uri:
image_uri = image_uri.strip()
return MEDIA_URL + image_uri if image_uri else None
3 changes: 0 additions & 3 deletions app/recipes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,3 @@ def temp_upload_image(instance, filename):
new_filename += "/" + filename
return new_filename

from config.settings import MEDIA_URL
def get_image_uri(image_uri):
return MEDIA_URL + image_uri if image_uri else None
3 changes: 2 additions & 1 deletion app/recipes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def post(self, request):


from .models import Temp_recipe, Temp_step, Unit
from .utils import create_file, get_image_uri
from .utils import create_file
from common.utils.image_utils import get_image_uri

class CreateTempImage(APIView):
def post(self, request):
Expand Down
6 changes: 3 additions & 3 deletions app/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def post(self, request):
{
"status": 200,
"message": "프로필 사진 저장 완료",
"image_url": MEDIA_URL + relative_image_path,
"image_url": get_image_uri(relative_image_path),
},
status=status.HTTP_200_OK,
)
Expand All @@ -244,7 +244,7 @@ def post(self, request):
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)


from common.utils.image_utils import get_image_uri
class MyPageView(APIView):
def get(self, request, id, cnt):
cnt = int(cnt)
Expand Down Expand Up @@ -279,7 +279,7 @@ def get(self, request, id, cnt):
"status": 200,
"message": "마이페이지 조회 완료",
"data": {
"image": MEDIA_URL + user_serializer.data["image"],
"image": get_image_uri(user_serializer.data["image"]),
"total_recipes_count": total_recipes_count,
"nickname": user_serializer.data["nickname"],
"recipes": recipe_serializer.data,
Expand Down

0 comments on commit ffa109a

Please sign in to comment.