Advertisement
Bamia

Untitled

Jul 20th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement