Created
March 21, 2022 05:30
-
-
Save JoeThunyathep/2142bfd9697747525f3b726557d74e05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="file" id="fs" multiple> <br> | |
<small id="target"></small> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prepare a function to decode base 64 unicode | |
function b64DecodeUnicode(str) { | |
return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) { | |
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | |
}).join('')); | |
} | |
// Create file reader Event Listener | |
const reader = new FileReader(); | |
reader.addEventListener('load', (event) => { | |
eventdata = event.target; | |
const result_base_64 = event.target.result; | |
const result_decoded = b64DecodeUnicode(result_base_64.split(',')[1]); | |
console.log(result_decoded); | |
document.getElementById("target").innerHTML = result_decoded; | |
}); | |
// Event Listener for file input | |
const fileSelect = document.getElementById('fs'); | |
fileSelect.addEventListener('change', (event) => { | |
const fileList = event.target.files; | |
for (const file of fileList) { | |
console.log("read file"); | |
reader.readAsDataURL(file); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment