diff --git a/app/common/utils/image_utils.py b/app/common/utils/image_utils.py new file mode 100644 index 0000000..65fcfc3 --- /dev/null +++ b/app/common/utils/image_utils.py @@ -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 \ No newline at end of file diff --git a/app/recipes/utils.py b/app/recipes/utils.py index 42d319f..2af218f 100644 --- a/app/recipes/utils.py +++ b/app/recipes/utils.py @@ -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 \ No newline at end of file diff --git a/app/recipes/views.py b/app/recipes/views.py index 2d0d527..e8acd78 100644 --- a/app/recipes/views.py +++ b/app/recipes/views.py @@ -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): diff --git a/app/users/views.py b/app/users/views.py index 42f0c77..458eeea 100644 --- a/app/users/views.py +++ b/app/users/views.py @@ -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, ) @@ -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) @@ -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,