Created
February 24, 2016 10:11
-
-
Save ekoneko/3616f503ed804a8d0df3 to your computer and use it in GitHub Desktop.
html5 get ctrl + v image
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
paste = (e) => { | |
var file, remoteImages; | |
if (typeof e.clipboardData.types === 'undefined' || e.clipboardData.types.length === 0 || e.clipboardData.types[0] !== 'Files') { | |
return; | |
} | |
file = e.clipboardData.items[0].getAsFile(); | |
render(file); | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
render = (file) => { | |
var reader = new FileReader(); | |
reader.onload = function(e) { | |
post(e.target.result) // `e.target.result` is image base64 string | |
} | |
reader.readAsDataURL(file); | |
} | |
body.addEventListener('paste', paste, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment