Refactor image upload process: set fixed ContentType for uploaded images and convert Base64 to Blob for file handling in useRefFiles hook.
This commit is contained in:
parent
1fe86746c1
commit
1cd24aeca9
@ -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({
|
||||
|
||||
@ -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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user