From fe9716ff178961bc35da3eaa10f1b8ad85a9ca9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Fri, 13 Feb 2026 16:44:12 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EB=B2=95=EC=9D=B8=EB=8F=84=EC=9E=A5=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EB=A5=BC=20base64=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(PHP=20uploa?= =?UTF-8?q?d=5Fmax=5Ffilesize=20=EC=A0=9C=ED=95=9C=20=EC=9A=B0=ED=9A=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- .../Controllers/ESign/EsignApiController.php | 10 +++++++--- resources/views/esign/dashboard.blade.php | 16 +++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ESign/EsignApiController.php b/app/Http/Controllers/ESign/EsignApiController.php index 212112ab..56bb3db5 100644 --- a/app/Http/Controllers/ESign/EsignApiController.php +++ b/app/Http/Controllers/ESign/EsignApiController.php @@ -54,11 +54,15 @@ public function getStamp(): JsonResponse public function uploadStamp(Request $request): JsonResponse { $request->validate([ - 'stamp_image' => 'required|image|max:5120', + 'stamp_image_data' => 'required|string', ]); $tenantId = session('selected_tenant_id', 1); - $file = $request->file('stamp_image'); + $imageData = base64_decode($request->input('stamp_image_data')); + + if (!$imageData) { + return response()->json(['success' => false, 'message' => '이미지 데이터가 올바르지 않습니다.'], 422); + } $path = "esign/{$tenantId}/stamps/company_stamp.png"; @@ -67,7 +71,7 @@ public function uploadStamp(Request $request): JsonResponse Storage::disk('local')->delete($path); } - Storage::disk('local')->put($path, file_get_contents($file->getRealPath())); + Storage::disk('local')->put($path, $imageData); TenantSetting::updateOrCreate( [ diff --git a/resources/views/esign/dashboard.blade.php b/resources/views/esign/dashboard.blade.php index 4bd3ec6a..b5c3a756 100644 --- a/resources/views/esign/dashboard.blade.php +++ b/resources/views/esign/dashboard.blade.php @@ -388,20 +388,26 @@ className={`px-3 py-1 text-sm rounded ${p === pagination.current_page ? 'bg-blue const handleUpload = async (e) => { const file = e.target.files[0]; if (!file) return; + if (file.size > 5 * 1024 * 1024) { alert('파일 크기는 5MB 이하여야 합니다.'); return; } setUploading(true); try { - const fd = new FormData(); - fd.append('stamp_image', file); + const base64 = await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result.split(',')[1]); + reader.onerror = reject; + reader.readAsDataURL(file); + }); const res = await fetch('/esign/contracts/stamp', { method: 'POST', - headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': csrfToken }, - body: fd, + headers: { ...getHeaders(), 'Content-Type': 'application/json' }, + body: JSON.stringify({ stamp_image_data: base64 }), }); const json = await res.json(); if (json.success) { setStamp(json.data); } else { - alert(json.message || '업로드에 실패했습니다.'); + const errMsg = json.errors?.stamp_image_data?.[0] || json.message || '업로드에 실패했습니다.'; + alert(errMsg); } } catch (e) { alert('업로드 중 오류가 발생했습니다.'); } setUploading(false);