예전 포스트에서 <input type="file"> 로 upload 받은 img File을 base64 형식의 data로 변환해보았는데 반대로 이번 포스트에선 base64 형식의 img data 를 다시 Blob 형태의 File로 다시 변환 해보았다.
준비된 base64 img data
아래 귀여운 고양이 이미지와 이 고양이 이미지를 base64로 인코딩한 데이터를 가져왔다.
사진 및에 img tag src 속성값 "data:image/jpg; base64,/9j/4aaqsK ~~~ " <- 요게 base64로 인코딩한 데이터 이다.
<img src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMSEBIQEBIVEBAVDxUQDxAPEBAPDw8PFRUXFhUVFRUYHSggGBolGxUVITEhJSkrLi4uFx8zODMsNygtLisBCgoKDg0OGhAQGy0fHR0rLS0rLS0rLS0tLS0tLSstLS0tLS0tLSstLS0tKystLS0tLS0rKystLS0rKy0rKy0rLf/AABEIARMAtwMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAAGAAEDBAUCBwj/xABAEAABAwIEAwUFBAkCBwAAAAABAAIRAwQFEiExBkFREyJhcaEyUoGRsQcUQsEVFiNTYoLR4fBjciUzg5KywvH/xAAaAQACAwEBAAAAAAAAAAAAAAAAAQIDBAUG/8QAJhEAAgIBBAIDAAIDAAAAAAAAAAECEQMSEyFRBDEUMkEiYQVCcf/aAAwDAQACEQMRAD8A8WSUwpLsUEAXuHqU1F6PbMhvwQXwvbd6fFHbGwFxvPdyO14CqAJcUauAWVY0ZcAtfHWy9ZlF+UynivbpBlpTthPZ2wACsV2gBZdti4IADHF3whEWAcOV7x0n9lSG7jqfILNPHKPM+C/ehXBkFwTBy9Ad9nNLLpVfm6nLE/JCWJ8N1KDyw6xsRzCjFpuvX/RRzRfozsyRK6Zh1QmACr1PA6mhKk4UTWRCssOzawrz8D02RDhNjAAIW22zEbLG8kr4FLIkeRYnYlhWO8r0viXDQZMLzS5ZDyPFdHx1uIoy5FEiconKbKpKFuXGAtey0Z3nRSNMlcutXIsw/AS7ktQ8OxyUbSHdnnLrVy5b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xkk6SAGSTpIASSSSAEmTp0AcpLpJAHKSdJADJk6ZADJ0kkCOYSTJ0wHSSBTpAIJ0kggY6UJJ4QAxTwkutEANCULrRJIZzCULvRKAgDiEoXeUJ8niiwojhKFJ2fiuSxAUcQmXeVLKmI4TKUU0uyQFEKSm7JJFhRDkS7MrtOEyJH2ZT5D0UoXQKBkGU9E0KzKaEAQJ1OkkBCFICnISgdEDEnSgJoCQx11C4hOAEAdBqfKllSypDFlTFqfIUxagCMhJIpKQjtqeFGlJSA7ITJpKSAIU4SSUiB0F0EkkhnTQnhJJAxQnhMkgB4+q7ASSSZJDgLlwSSSQ2IBcuSSTEOE8p0kAMSkEkkgOXBcgJJJgdAJ4SSSGIhJJJAH/9k="
const convertBase64ImgToImgFile = (data, fileName) => {
const arr = data.split(',') // arr = [data:image/jpg;base64 , /9j/4AAQSkZJRgABAQAAAQABA ...]
const [mime, binaryData] = [arr[0].match(/:(.*?);/)[1], atob(arr[1])] // atob는 base64 data를 decode한다
// mime = image/jpg
// binrayData = image의 binary data (atob는 window 내장 객체로 base64 data를 decode하는 메소드이다.)
let n = binaryData.length
let unit8Array = new Uint8Array(n);
// binrayData를 다루기 위해 unit8Array Typpedarray 이용
// 이미지 데이터는 각 픽셀단위로 0~255로 표현되기 때문에 unit8Array를 이용하는 게 효율적
while (n--) {
unit8Array[n] = binaryData.charCodeAt(n)
// charCodeAt(n)은 array의 index=n 문자의 유니 코드 값을 반환한다.
}
return new File([unit8Array], fileName, { type: mime })
}
const imgFile = convertBase64ImgToImgFile(base64data)
console.log('imgFile:',imgFile)
img File 객체 console.log로 찍어보기
위코드에서 변환한 imgFile을 console.log로 찍어보면 아래와 같이 나타난다.
imgFile: 옆에 File 로 찍힌걸 확인할 수 있다. File은 웹페이지에서 자바스크립트로 파일의 내용에 접근 할 수 있도록 한다고 한다. ( MDN 내용 ) 즉 실제 파일을 다루기 위해 정의된 객체정도로 이해하면 될 것 같다.
SIZE는 6464로 나타나는데 이는 파일의 용량이 6464Btye임을 나타낸다.
type은 "image/jpg"로 되어있는데 이는 MIME type을 나타낸다
그리고 Prototype: Blob도 하위에 확인되는데 File은 Blob을 확장한 개념이라고 한다. 그럼 여기서 Blob이란 무엇일까?
Blob 객체는 파일류의 불변하는 미가공 데이터를 나타낸다 ( MDN 내용 ) 라고 되어 있는데 말 그대로 실제 이미지나, 오디오, 동영상 과 같은 파일의 데이터이다. Blob은 텍스트와 이진데이터 형태로 읽을 수 있다. 참고로 Blob의 데이터를 이진데이터로 읽어 화면에 출력 하면 우리가 알수없는 문자들이 출력된다. 텍스트로 읽어오는 방법은 여러가지가 있는데 그중 하나가 FileReader.readAsDataURL(blob)이다 (https://developer.mozilla.org/ko/docs/Web/API/FileReader/readAsDataURL) 이 메서드를 사용할 시 base64 형태로 인코딩을 한다.
참고
https://developer.mozilla.org/ko/docs/Web/API/File
https://developer.mozilla.org/ko/docs/Web/API/atob
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
https://developer.mozilla.org/ko/docs/Web/API/Blob
https://developer.mozilla.org/ko/docs/Web/API/FileReader/readAsDataURL
'⭐FE' 카테고리의 다른 글
Next.js 프로젝트 메모리 사용량 확인 (1) | 2024.12.20 |
---|---|
Nextjs 터보팩? (0) | 2024.11.18 |
[JS] 미리보기 이미지 구현하기 ( FileReader, FileReader.readAsDataURL() 이용 ) (0) | 2024.05.15 |
Yarn berry Package Manager 설치방법 (0) | 2024.02.12 |
react lazy loading 처리 방법 ( suspense와 lazy 이용 ) (0) | 2024.01.24 |