-
-
Save juanlatorre/2b9804879aafffe5bad669272d00b676 to your computer and use it in GitHub Desktop.
React-Dropzone get image width, height and base64 data
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
const onDrop = useCallback((acceptedFiles) => { | |
const file = acceptedFiles.find(f => f) | |
const i = new Image() | |
i.onload = () => { | |
let reader = new FileReader() | |
reader.readAsDataURL(file) | |
reader.onload = () => { | |
console.log({ | |
src: file.preview, | |
width: i.width, | |
height: i.height, | |
data: reader.result | |
}) | |
} | |
} | |
i.src = file.preview | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment