Last active
May 11, 2017 17:55
-
-
Save kuczmama/c89586e19d471f9df7fa20b9ce3b11aa to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<!-- Replace your api_key, upload_preset, and cloud_name. For more information please see the blog post at --> | |
<html> | |
<body> | |
<script type="text/javascript"> | |
let doUpload = () => { | |
var files = document.getElementById("myid").files; | |
var formData = new FormData(); | |
for (file of files) { | |
formData.append('file', file); | |
} | |
formData.append("api_key", **api_key**); | |
formData.append("upload_preset", **upload_preset**); | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', "https://api.cloudinary.com/v1_1/**cloud_name**/image/upload", true); | |
xhr.onload = function () { | |
if (xhr.readyState === xhr.DONE) { | |
if (xhr.status === 200) { | |
console.log(JSON.parse(xhr.responseText)); | |
} else { | |
console.log("error"); | |
} | |
} | |
}; | |
xhr.send(formData); | |
} | |
</script> | |
Upload a File: | |
<input type="file" id="myid" /> | |
<button type="submit" onClick="doUpload()">Upload</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment