Skip to content

Instantly share code, notes, and snippets.

@amirulabu
Created September 16, 2017 12:51
Show Gist options
  • Save amirulabu/f6d98e63e8652757ef3ef265f6131dce to your computer and use it in GitHub Desktop.
Save amirulabu/f6d98e63e8652757ef3ef265f6131dce to your computer and use it in GitHub Desktop.
uploading images to imgur using jquery
var form = new FormData();
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.imgur.com/3/image",
"method": "POST",
"headers": {
"authorization": "Client-ID YOUR_CLIENT_ID"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data"
}
$("#upload-button").on('click',function(e){
e.preventDefault();
console.log($("#upload-image")[0].files[0]);
form.append("image", $("#upload-image")[0].files[0] );
settings.data = form;
$.ajax(settings).done(function (response) {
console.log(response.data.link);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment