我正在尝试在创建 firebase 用户时上传用户头像,在此处创建用户后
auth.createUserWithEmailAndPassword(this.state.email,this.state.password)
.then(credential=>{
const photoUrl = this.handleUpload(credential)
})
我创建了一个句柄上传函数,它在下面返回一个 photoUrl
handleUpload=(credential)=>{
const {avatar} = this.state;
const upload = storage.ref(`avatars/${credential.user.uid}`).put(avatar)
upload.on('state_changed',(snapshot)=>{
let progress = (snapshot.bytesTransferred/snapshot.totalBytes)*100;
console.log('Upload is ' + progress + '% done');
},(e)=>{
console.log(e)
},()=>{
return storage.ref("avatars").child(`${credential.user.uid}`).getDownloadURL()
})
}
并且filepond UI实例在UI中声明如下
const { ....,avatar,....} = this.state;
<FilePond
ref={ref => this.pond = ref}
files={avatar}
fileValidateTypeLabelExpectedTypes="Invalid File Type"
imagePreviewMaxFileSize='3MB'
imageValidateSizeMinWidth="400"
imageValidateSizeMaxWidth="1024"
imageValidateSizeMinHeight="400"
imageValidateSizeMaxHeight="1024"
imagePreviewTransparencyIndicator="green"
maxFileSize='3MB'
labelIdle={'Drag & Drop your Profile Picture or <span class="filepond--label-action"> Browse </span>'}
acceptedFileTypes={['image/png', 'image/jpeg']}
onupdatefiles={fileItems => {
this.setState({
avatar: fileItems.map(fileItem => fileItem.file)
});
}}
/>
但我得到了预期的 blob 或文件错误......我该如何解决这个问题?