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 a74a7f8a..90c96f30 100644 --- a/src/hooks/common/useRefFiles.js +++ b/src/hooks/common/useRefFiles.js @@ -8,7 +8,6 @@ import { useCanvas } from '@/hooks/useCanvas' import { deleteBackGroundImage, setBackGroundImage } from '@/lib/imageActions' import { settingModalFirstOptionsState } from '@/store/settingAtom' import { popSpinnerState } from '@/store/popupAtom' -import Config from '@/config/config.export' /** * λ°°κ²½ 이미지 관리 @@ -239,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: `${Config().baseUrl}/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 = {