Created
March 13, 2021 18:41
-
-
Save Kaoschuks/1a15fa0ab1b84055d62fb7822f6c7cec to your computer and use it in GitHub Desktop.
cloudinary api upolad
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
| 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