Created
September 16, 2017 12:51
-
-
Save amirulabu/f6d98e63e8652757ef3ef265f6131dce to your computer and use it in GitHub Desktop.
uploading images to imgur using jquery
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
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