Created
July 6, 2020 16:05
-
-
Save smitroshin/80886ff60f1c5c7dca78d18b145afd8f to your computer and use it in GitHub Desktop.
Reading file contents from file input via FileReader
This file contains hidden or 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
/** | |
* Source: https://react-dropzone.js.org/ | |
*/ | |
const onDrop = () => (acceptedFiles) => { | |
acceptedFiles.forEach((file) => { | |
const reader = new FileReader() | |
reader.onabort = () => console.log('file reading was aborted') | |
reader.onerror = () => console.log('file reading has failed') | |
reader.onload = () => { | |
// Do whatever you want with the file contents | |
const binaryStr = reader.result | |
console.log(binaryStr) | |
} | |
reader.readAsArrayBuffer(file) | |
}) | |
} | |
// Call onDrop on input change event |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment