Skip to content

Instantly share code, notes, and snippets.

@kuczmama
Last active May 11, 2017 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuczmama/c89586e19d471f9df7fa20b9ce3b11aa to your computer and use it in GitHub Desktop.
Save kuczmama/c89586e19d471f9df7fa20b9ce3b11aa to your computer and use it in GitHub Desktop.
<!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