Reputation: 1749
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.
Upvotes: 1
Views: 14048
Reputation: 105
Referring to dan's solution, it works for me after 2 amendments for Upload Function:-
Upload Function
var uploadToStorage = (imageURL) => {
getFileBlob(imageURL, blob =>{
firebase.storage().ref().put(blob).then(function(snapshot) {
console.log('Uploaded a blob or file!');
})
})
}
Upvotes: 4
Reputation: 336
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();
};
Upvotes: 9