728x90
Base64 인코딩은 Binary Data를 Text로 변경하는 인코딩이다.
atob() → Base64 인코딩된 문자열 데이터를 디코딩한다.
atob(encodedData);
// base64 인코딩된 데이터를 담은 이진 문자열
charCodeAt() → index에 해당하는 문자의 unicode 값을 리턴한다.
"ABC".charCodeAt(0);
// "ABC"에 0번째 인덱스인 "A"의 unicode 값을 리턴한다.
var bs64 = data;
const byteCharacters = atob(bs64);
const byteNumbers = new Array(byteCharacters.length);
for(let i=0; i<byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], {type: 'image/png'});
const file = new File([byteArray], 'filename', {type: 'image/png'});
.base64를 binary 문자열로 인코딩 한 후, 해당 문자의 unicode를 저장한 배열을 만든다.
728x90
'Programming > JavaScript' 카테고리의 다른 글
Map 객체 살펴보기 (0) | 2024.03.03 |
---|---|
String 객체 살펴보기 (2) | 2024.03.01 |
Array 객체 살펴보기 (0) | 2024.02.19 |
일치 연산자(Strict equality operators) (0) | 2024.02.17 |