Skip to content

Instantly share code, notes, and snippets.

@davidicus
Created November 12, 2020 01:07
Show Gist options
  • Save davidicus/9c0c0d433d21b8014f999b1763405e72 to your computer and use it in GitHub Desktop.
Save davidicus/9c0c0d433d21b8014f999b1763405e72 to your computer and use it in GitHub Desktop.
Drag and drop file upload and conversion to data URL
const handleOnChange = (e, callback) => {
console.log('onChanged');
const fReader = new FileReader();
fReader.readAsDataURL(
e.type === 'drop' ? e.dataTransfer.files[0] : e.target.files[0]
);
fReader.onloadend = (event) => {
callback(event.target.result);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment