Created
August 11, 2011 23:16
-
-
Save gaving/1141046 to your computer and use it in GitHub Desktop.
post a blob directly to imgur
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | |
<title>paste blob to imgur</title> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<script type="text/javascript"> | |
$(document).bind('paste', function(e) { | |
var e = e.originalEvent; | |
if (e && e.clipboardData && e.clipboardData.getData) { | |
var items = e.clipboardData.items; | |
var blob = items[0].getAsFile(); | |
if (!blob || !blob.type.match(/image.*/)) { | |
alert('Cant get as file or not an image'); | |
return; | |
} | |
var fd = new FormData(); | |
fd.append("image", blob); | |
fd.append("key", "cd5eaa68ce7de375ad377c439847de87"); | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", "http://api.imgur.com/2/upload.json"); | |
xhr.onload = function() { | |
var url = JSON.parse(xhr.responseText).upload.links.original; | |
console.log(url); | |
alert(url); | |
} | |
xhr.send(fd); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
Paste here! | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment