Last active
October 13, 2016 20:20
-
-
Save GeoffreyPlitt/db1bf983112b734073e74962a182eac1 to your computer and use it in GitHub Desktop.
Cloudinary REST upload via fetch()
This file contains 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
function upload_to_cloudinary(uri) { | |
let timestamp = (Date.now() / 1000 | 0).toString() | |
let hash_string = 'timestamp=' + timestamp + cloudinary_config.api_secret | |
let signature = CryptoJS.SHA1(hash_string).toString() | |
let upload_url = 'https://api.cloudinary.com/v1_1/' + cloudinary_config.cloud_name + `/video/upload` | |
const formdata = new FormData() | |
formdata.append('file', {uri, type: 'video/mp4', name: 'upload.mp4'}) | |
formdata.append('eager', 'c_fill,h_1280,w_720|c_fill,h_853,w_480') | |
formdata.append('eager_async', true) | |
formdata.append('timestamp', timestamp) | |
formdata.append('api_key', cloudinary_config.api_key) | |
formdata.append('signature', signature) | |
return fetch(upload_url, { | |
method: 'POST', | |
body: formdata | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment