Skip to content

Instantly share code, notes, and snippets.

@Kaoschuks
Created March 13, 2021 18:41
Show Gist options
  • Save Kaoschuks/1a15fa0ab1b84055d62fb7822f6c7cec to your computer and use it in GitHub Desktop.
Save Kaoschuks/1a15fa0ab1b84055d62fb7822f6c7cec to your computer and use it in GitHub Desktop.
cloudinary api upolad
let cloudinary = {
upload_preset: '',
url: ''
}
async upload(file: Blob) {
return await new Promise((resolve, reject) => {
try {
const myFormData = new FormData();
myFormData.append("file", file);
myFormData.append("upload_preset", cloudinary.upload_preset);
myFormData.append("skipAuthorization", "true");
fetch(cloudinary.url, myFormData)
.then(data => {
resolve({
url: data['secure_url']
})
}).catch((ex: any) => {
throw new Error(ex);
})
}catch(ex) {
console.log(ex);
reject({
error: "file upload error"
})
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment