Fix file upload path issues with Korean filenames

- Replace complex filename sanitization with simple timestamp-based naming
- Generate safe filenames using timestamp and random strings
- Store original filename in database, use safe names in storage
- Remove Korean characters and special characters from storage paths
- Preserve file extensions for proper file type handling

This resolves: "Invalid key" errors with Korean filenames in Supabase Storage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-19 14:16:52 +09:00
parent c647cbdc6c
commit 9ba38e69c2

View File

@@ -69,6 +69,15 @@ class FileManager {
return Date.now().toString(36) + Math.random().toString(36).substr(2);
}
// 파일 확장자 추출 (안전한 형태로)
getFileExtension(fileName) {
const lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex > 0 && lastDotIndex < fileName.length - 1) {
return fileName.substring(lastDotIndex).toLowerCase();
}
return ''; // 확장자가 없는 경우
}
// 인증 관련 메서드들
async initializeAuth() {
try {
@@ -511,9 +520,10 @@ class FileManager {
const response = await fetch(attachment.data);
const blob = await response.blob();
// 파일 경로 생성 (사용자별/파일ID별 폴더 구조)
const fileName = `${Date.now()}_${Math.random().toString(36).substr(2, 9)}_${attachment.name}`;
const filePath = `${this.currentUser.id}/${fileId}/${fileName}`;
// 안전한 파일명 생성 (고유한 이름으로 저장, 원본명은 DB에 저장)
const fileExtension = this.getFileExtension(attachment.name);
const safeFileName = `${Date.now()}_${Math.random().toString(36).substr(2, 9)}${fileExtension}`;
const filePath = `${this.currentUser.id}/${fileId}/${safeFileName}`;
// Supabase Storage에 업로드
const uploadResult = await SupabaseHelper.uploadFile(blob, filePath);