Created
May 14, 2013 02:16
-
-
Save auggernaut/5573158 to your computer and use it in GitHub Desktop.
Shortest javascript image uploaded 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
//ADD IMAGE | |
//http://hacks.mozilla.org/2011/03/the-shortest-image-uploader-ever/ | |
var files = $('input[id = upImage]')[0].files; | |
var file = files[0]; | |
if (!file || !file.type.match(/image.*/)) return; | |
var fd = new FormData(); | |
fd.append("image", file); | |
fd.append("type", "file"); | |
fd.append("name", "test"); | |
fd.append("description", "tests"); | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", "https://api.imgur.com/3/image"); // Boooom! | |
xhr.setRequestHeader("Authorization", "Client-ID 0ea1384c01b6dcf"); | |
xhr.onload = function () { | |
var url = JSON.parse(xhr.responseText).data.link; | |
$("#zImage").attr("src", url); | |
}; | |
xhr.send(fd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment