我有一个blob网址,例如:
blob:http://localhost:4200/06a6baa9-b7ff-4171-9dc2-a1caed35e099
而当进入
this.storage.ref('users/' + uid + '/mainPhoto').put(imageURL))
我收到此错误:
Firebase存储:索引0处的put中的参数无效:预期的Blob或文件 .
您需要从blob网址上传blob,然后将其上传到firebase存储
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(); };
你不需要传递blob的url,只需传递blob本身 .
var file = ... // use the Blob or File API ref.put(file).then(function(snapshot) { console.log('Uploaded a blob or file!'); });
请参阅Firebase File Upload处的'Upload from a Blob or File'部分 .
2 回答
您需要从blob网址上传blob,然后将其上传到firebase存储
Upload Function :
getBlob Function :
你不需要传递blob的url,只需传递blob本身 .
请参阅Firebase File Upload处的'Upload from a Blob or File'部分 .