Created
February 10, 2017 11:55
-
-
Save schabluk/808f8691720d3a0e0e200a333bc61ecc to your computer and use it in GitHub Desktop.
React-Dropzone get image width, height and base64 data
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
onDrop = (acceptedFiles, rejectedFiles) => { | |
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