问题
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
putat index 0: Expected Blob or File.
回答1:
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();
};
回答2:
You don't need to pass the blob's url, just pass the blob itself.
var file = ... // use the Blob or File API
ref.put(file).then(function(snapshot) {
console.log('Uploaded a blob or file!');
});
See the 'Upload from a Blob or File' section at Firebase File Upload.
来源:https://stackoverflow.com/questions/48862777/firebase-storage-upload-blob-url