SHARE
TWEET

Untitled

Bamia Jul 20th, 2019 (edited) 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uploadImage = (uri) => {
  2.     const imagesRef = firebase.storage().ref().child('images').child(uuid.v4());
  3.    
  4.     const downloadURLPromise = new Promise((resolve, reject) => {
  5.  
  6.       const xhr = new XMLHttpRequest();
  7.       xhr.onload = function() {
  8.         const blob = xhr.response;
  9.         console.log(blob);
  10.         var uploadTask = imagesRef.put(blob);
  11.      
  12.         uploadTask.then((snapshot) => {
  13.           snapshot.ref.getDownloadURL().then(function(downloadURL) {
  14.             console.log('File available at', downloadURL);
  15.             resolve(downloadURL);
  16.            
  17.           }).catch( (error) => {
  18.             reject(error);
  19.           });
  20.         }).catch( (error) => {
  21.           reject(error);
  22.         });
  23.       };
  24.       xhr.onerror = function(error) {
  25.         reject(error);
  26.       };
  27.  
  28.       xhr.responseType = 'blob';
  29.       xhr.open('GET', uri, true);
  30.       xhr.send(null);
  31.  
  32.     });
  33.  
  34.    return downloadURLPromise;
  35.   };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top