From 9ba38e69c2a361f0ee80b2902b70a7ffaae856a8 Mon Sep 17 00:00:00 2001 From: vibsin9322 Date: Tue, 19 Aug 2025 14:16:52 +0900 Subject: [PATCH] Fix file upload path issues with Korean filenames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- script.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 04e901d..8f7072a 100644 --- a/script.js +++ b/script.js @@ -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);