1

I have a blob url such as :

blob:http://localhost:4200/06a6baa9-b7ff-4171-9dc2-a1caed35e099

and when passing into

  this.storage.ref('users/' + uid + '/mainPhoto').put(imageURL))

I am receiving this error:

Firebase Storage: Invalid argument in put at index 0: Expected Blob or File.

2 Answers 2

9

You need to upload the blob from the blob url, and than upload it to firebase storage

Upload Function:

uploadToStorage = (imageURL) = >{

     getFileBlob(imageURL, blob =>{
        firebase.storage().ref().put(blob).then(function(snapshot) {
           console.log('Uploaded a blob or file!');
        })
    })
}

getBlob Function:

var getFileBlob = function (url, cb) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url);
      xhr.responseType = "blob";
      xhr.addEventListener('load', function() {
        cb(xhr.response);
      });
      xhr.send();
    };
Sign up to request clarification or add additional context in comments.

2 Comments

this is the best solution when using expo.. for some reason now fetch does not work..
Where does the getFileBlob come from?
4

Referring to dan's solution, it works for me after 2 amendments for Upload Function:-

  1. there should be a 'var' in front of "uploadToStorage = (imageURL)..."
  2. there should not have spacing for '=>'

Upload Function

var uploadToStorage = (imageURL) => {

     getFileBlob(imageURL, blob =>{
        firebase.storage().ref().put(blob).then(function(snapshot) {
           console.log('Uploaded a blob or file!');
        })
    })
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.