Skip to content

Instantly share code, notes, and snippets.

@guillaumemorin
Last active April 4, 2017 13:05
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 guillaumemorin/09feab5ad1bf15de35c5125a0dba38cf to your computer and use it in GitHub Desktop.
Save guillaumemorin/09feab5ad1bf15de35c5125a0dba38cf to your computer and use it in GitHub Desktop.
react native cloudinary upload
var CryptoJS = require('crypto-js');
function uploadImage(uri) {
  let timestamp = (Date.now() / 1000 | 0).toString();
  let api_key = 'your api key'
  let api_secret = 'your api secret'
  let cloud = 'your cloud name'
  let hash_string = 'timestamp=' + timestamp + api_secret
  let signature = CryptoJS.SHA1(hash_string).toString();
  let upload_url = 'https://api.cloudinary.com/v1_1/' + cloud + '/image/upload'

  let xhr = new XMLHttpRequest();
  xhr.open('POST', upload_url);
  xhr.onload = () => {
    console.log(xhr);
  };
  let formdata = new FormData();
  formdata.append('file', {uri: uri, type: 'image/png', name: 'upload.png'});
  formdata.append('timestamp', timestamp);
  formdata.append('api_key', api_key);
  formdata.append('signature', signature);
  xhr.send(formdata);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment