Created
January 5, 2021 03:58
-
-
Save gemblue/ec87bc5fda35c26f4476fa01a5666d94 to your computer and use it in GitHub Desktop.
ImgBB Uploader Js
This file contains hidden or 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
<h1>Test</h1> | |
<input type="file" id="input_img" accept="image/*"> | |
<button class="btn-upload">Upload</button> | |
<div class="message"></div> | |
<div class="output"></div> | |
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script> | |
<script> | |
$('.btn-upload').click(function(){ | |
$('.message').html('Processing ..<br/>'); | |
var file = document.getElementById('input_img'); | |
var form = new FormData(); | |
form.append("image", file.files[0]) | |
var settings = { | |
"url": "https://api.imgbb.com/1/upload?key=762894e2014f83c023b233b2f10395e2", | |
"method": "POST", | |
"timeout": 0, | |
"processData": false, | |
"mimeType": "multipart/form-data", | |
"contentType": false, | |
"data": form | |
}; | |
$.ajax(settings).done(function (response) { | |
$('.message').html('Done ..<br/>'); | |
let data = JSON.parse(response); | |
$('.output').html(`<img src="${data.data.display_url}" />`); | |
console.log(data); | |
}); | |
return false; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment