From cb14b3bb78ff0100b0ddd3d0e2db5a01e8396b58 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Tue, 27 May 2025 15:20:30 +0900 Subject: [PATCH] Update converter API URL in development and production environment files --- .env.development | 2 +- src/app/api/image/cad/route.js | 3 ++- src/hooks/common/useRefFiles.js | 30 ++++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.env.development b/.env.development index 8890f8d4..08261ec0 100644 --- a/.env.development +++ b/.env.development @@ -2,7 +2,7 @@ NEXT_PUBLIC_API_SERVER_PATH="https://dev-api.hanasys.jp" NEXT_PUBLIC_HOST_URL="//1.248.227.176:4000" -NEXT_PUBLIC_API_HOST_URL="http://1.248.227.176:5000" +NEXT_PUBLIC_API_HOST_URL="http://localhost:3000" SESSION_SECRET="i3iHH1yp2/2SpQSIySQ4bpyc4g0D+zCF9FAn5xUG0+Y=" diff --git a/src/app/api/image/cad/route.js b/src/app/api/image/cad/route.js index b7d64a50..a0e60a4c 100644 --- a/src/app/api/image/cad/route.js +++ b/src/app/api/image/cad/route.js @@ -11,9 +11,10 @@ const s3 = new S3Client({ }) const uploadImage = async (file) => { + console.log('πŸš€ ~ uploadImage ~ file:', file) const Body = Buffer.from(await file.arrayBuffer()) const Key = `cads/${file.name}` - const ContentType = file.ContentType + const ContentType = 'image/png' await s3.send( new PutObjectCommand({ diff --git a/src/hooks/common/useRefFiles.js b/src/hooks/common/useRefFiles.js index d13e7213..366f5589 100644 --- a/src/hooks/common/useRefFiles.js +++ b/src/hooks/common/useRefFiles.js @@ -238,14 +238,40 @@ export function useRefFiles() { const res = await post({ url: converterUrl, data: formData }) console.log('πŸš€ ~ handleUploadConvertRefFile ~ res:', res) + // Convert Base64 to Blob + const base64Data = res.Files[0].FileData + const byteCharacters = atob(base64Data) + const byteArrays = [] + + for (let offset = 0; offset < byteCharacters.length; offset += 512) { + const slice = byteCharacters.slice(offset, offset + 512) + const byteNumbers = new Array(slice.length) + + for (let i = 0; i < slice.length; i++) { + byteNumbers[i] = slice.charCodeAt(i) + } + + const byteArray = new Uint8Array(byteNumbers) + byteArrays.push(byteArray) + } + + const blob = new Blob(byteArrays, { type: 'image/png' }) + + // Create File object from Blob + const convertImg = new File([blob], res.Files[0].FileName, { type: 'image/png' }) + + const newFormData = new FormData() + newFormData.append('file', convertImg) + /** μΊλ“œ 도면 파일 μ—…λ‘œλ“œ */ const result = await post({ url: `${process.env.NEXT_PUBLIC_API_HOST_URL}/api/image/cad`, - data: res, + data: newFormData, }) console.log('πŸš€ ~ handleUploadConvertRefFile ~ result:', result) - setCurrentBgImage(`${process.env.NEXT_PUBLIC_AWS_S3_BASE_URL}/${res.fileName}`) + // setCurrentBgImage(`${process.env.NEXT_PUBLIC_AWS_S3_BASE_URL}/${result.fileName}`) + setCurrentBgImage(result.filePath) setRefImage(file) const params = {