Skip to content

Commit 4a6615a

Browse files
authored
1st_pre
1 parent ccdda1a commit 4a6615a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

routers/file.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ~/noteflow/Backend/routers/file.py
2+
13
import os
24
import io
35
import whisper
@@ -17,9 +19,6 @@
1719
from models.note import Note as NoteModel
1820
from utils.jwt_utils import get_current_user
1921

20-
# 추가: 파일명 인코딩용
21-
import urllib.parse
22-
2322
# -------------------------------
2423
# 1) EasyOCR 라이브러리 임포트 (GPU 모드 활성화)
2524
# -------------------------------
@@ -56,6 +55,7 @@
5655
trust_remote_code=True
5756
)
5857

58+
# 업로드 디렉토리 설정
5959
BASE_UPLOAD_DIR = os.path.join(
6060
os.path.dirname(os.path.abspath(__file__)),
6161
"..",
@@ -80,9 +80,11 @@ async def upload_file(
8080
orig_filename: str = upload_file.filename or "unnamed"
8181
content_type: str = upload_file.content_type or "application/octet-stream"
8282

83+
# 사용자별 디렉토리 생성
8384
user_dir = os.path.join(BASE_UPLOAD_DIR, str(current_user.u_id))
8485
os.makedirs(user_dir, exist_ok=True)
8586

87+
# 원본 파일명 그대로 저장 (동명이인 방지)
8688
saved_filename = orig_filename
8789
saved_path = os.path.join(user_dir, saved_filename)
8890
if os.path.exists(saved_path):
@@ -97,13 +99,15 @@ async def upload_file(
9799
break
98100
counter += 1
99101

102+
# 파일 저장
100103
try:
101104
with open(saved_path, "wb") as buffer:
102105
content = await upload_file.read()
103106
buffer.write(content)
104107
except Exception as e:
105108
raise HTTPException(status_code=500, detail=f"파일 저장 실패: {e}")
106109

110+
# DB에 메타데이터 기록
107111
new_file = FileModel(
108112
user_id=current_user.u_id,
109113
folder_id=folder_id,
@@ -173,9 +177,6 @@ def download_file(
173177
if not os.path.exists(file_path):
174178
raise HTTPException(status_code=404, detail="서버에 파일이 존재하지 않습니다.")
175179

176-
# 원본 파일명 UTF-8 URL 인코딩 처리
177-
quoted_name = urllib.parse.quote(file_obj.original_name, safe='')
178-
content_disposition = f"inline; filename*=UTF-8''{quoted_name}"
179180
# original_name 을 percent-encoding 해서 ASCII 만으로 헤더 구성
180181
filename_quoted = quote(file_obj.original_name)
181182
content_disposition = f"inline; filename*=UTF-8''{filename_quoted}"

0 commit comments

Comments
 (0)