Skip to content

Instantly share code, notes, and snippets.

@auggernaut
Created May 14, 2013 02:16
Show Gist options
  • Save auggernaut/5573158 to your computer and use it in GitHub Desktop.
Save auggernaut/5573158 to your computer and use it in GitHub Desktop.
Shortest javascript image uploaded to imgur.
//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