Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uploadImage = (uri) => {
- const imagesRef = firebase.storage().ref().child('images').child(uuid.v4());
- const downloadURLPromise = new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.onload = function() {
- const blob = xhr.response;
- console.log(blob);
- var uploadTask = imagesRef.put(blob);
- uploadTask.then((snapshot) => {
- snapshot.ref.getDownloadURL().then(function(downloadURL) {
- console.log('File available at', downloadURL);
- resolve(downloadURL);
- }).catch( (error) => {
- reject(error);
- });
- }).catch( (error) => {
- reject(error);
- });
- };
- xhr.onerror = function(error) {
- reject(error);
- };
- xhr.responseType = 'blob';
- xhr.open('GET', uri, true);
- xhr.send(null);
- });
- return downloadURLPromise;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement