Skip to content

Instantly share code, notes, and snippets.

@GeoffreyPlitt
Last active October 13, 2016 20:20
Show Gist options
  • Save GeoffreyPlitt/db1bf983112b734073e74962a182eac1 to your computer and use it in GitHub Desktop.
Save GeoffreyPlitt/db1bf983112b734073e74962a182eac1 to your computer and use it in GitHub Desktop.
Cloudinary REST upload via fetch()
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