Firebase存储-上传Blob网址 [英] Firebase Storage - Upload Blob Url
本文介绍了Firebase存储-上传Blob网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Blob网址,例如:
I have a blob url such as :
blob:http://localhost:4200/06a6baa9-b7ff-4171-9dc2-a1caed35e099
以及进入
this.storage.ref('users/' + uid + '/mainPhoto').put(imageURL))
我收到此错误:
Firebase存储:
put
中索引0处的参数无效:预期的Blob或文件.
Firebase Storage: Invalid argument in
put
at index 0: Expected Blob or File.
推荐答案
您需要从Blob网址上传Blob, 然后将其上传到Firebase存储
You need to upload the blob from the blob url, and than upload it to firebase storage
上传功能:
uploadToStorage = (imageURL) = >{
getFileBlob(imageURL, blob =>{
firebase.storage().ref().put(blob).then(function(snapshot) {
console.log('Uploaded a blob or file!');
})
})
}
getBlob函数:
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();
};
这篇关于Firebase存储-上传Blob网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文