Skip to content

Instantly share code, notes, and snippets.

@revskill10
Forked from stolinski/react-cloudinary.js
Created October 20, 2018 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revskill10/0443e64fe23fd4191f4c02f5b1d03705 to your computer and use it in GitHub Desktop.
Save revskill10/0443e64fe23fd4191f4c02f5b1d03705 to your computer and use it in GitHub Desktop.
Client side Image Upload To Cloudinary React Dropzone
// get's called from react dropzone when file is dropped
onImageDrop = (files) => {
this.handleImageUpload(files[0]);
}
async handleImageUpload(file) {
const data = new FormData();
data.append('file', file);
data.append('upload_preset', CLOUDINARY_UPLOAD_PRESET);
const upload = await fetch(CLOUDINARY_UPLOAD_URL, {
method: 'POST',
body: data,
});
const image = await upload.json();
// then do something with image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment