[feat] negodata/backend: 상품 이미지 업로드(Azure Blob) 엔드포인트 추가
POST /v1/item/image — SAS 토큰을 URL에 붙여 httpx PUT 으로 Azure Blob 업로드. 이미지 타입/용량 검증 + IMAGE_* 에러코드. config 에 azure_blob_base_url/sas/root 추가. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
49e682d693
commit
3280cab088
10 files changed
+287
-15
No files matched your search
@@ -1,12 +1,14 @@
|
||||
import uuid
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi import Depends, UploadFile
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import items
|
||||
from common.enums import DBWRType, ErrorType
|
||||
from common.logger import LOG
|
||||
from common.models.gmodel import PageParams
|
||||
from services.azure_blob_client import is_allowed_image, upload_image as blob_upload_image
|
||||
from config.server_configs import storage_config
|
||||
from crud.item_crud import IItemCRUD, ItemCRUD
|
||||
from router.v1.item.protocol import (
|
||||
ItemCategory,
|
||||
@@ -15,6 +17,7 @@ from router.v1.item.protocol import (
|
||||
Res_DeleteItem,
|
||||
Res_Item,
|
||||
Res_ItemCategories,
|
||||
Res_ItemImage,
|
||||
Res_ItemList,
|
||||
)
|
||||
|
||||
@@ -162,3 +165,28 @@ class ItemService:
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
async def upload_image(self, company_id: str, file: UploadFile) -> Res_ItemImage:
|
||||
"""상품 이미지를 Azure Blob 에 올리고 image_url 을 돌려준다.
|
||||
DB 는 건드리지 않는다 — 프론트가 이 URL 을 create/update 의 image_url 로 실어 보낸다."""
|
||||
res = Res_ItemImage()
|
||||
content_type = file.content_type or ""
|
||||
if not is_allowed_image(content_type):
|
||||
res.result.SetResult(ErrorType.IMAGE_INVALID_TYPE)
|
||||
return res
|
||||
|
||||
content = await file.read()
|
||||
if len(content) > storage_config.max_image_mb * 1024 * 1024:
|
||||
res.result.SetResult(ErrorType.IMAGE_TOO_LARGE)
|
||||
return res
|
||||
|
||||
try:
|
||||
res.image_url = await blob_upload_image(company_id, content, content_type)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
res.result.SetResult(ErrorType.IMAGE_UPLOAD_FAILED)
|
||||
return res
|
||||
|
||||
res.filename = file.filename
|
||||
res.size = len(content)
|
||||
return res
|
||||
Reference in new issue
Block a user