类型错误:将图像从本地本机上传到Firebase时,网络请求失败

时间:2019-03-07 07:22:51

标签: firebase react-native

我正在尝试将图像从我的本机应用程序上载到Firebase,但是我遇到此错误已有2天了,我也没有找到原因,我之前也做过这件事,但是这次是引起这个问题的。 这是我的代码,

_pickImageFront = async () => {
          let pickerResult = await ImagePicker.launchImageLibraryAsync({
            allowsEditing: true,
            aspect: [4, 3],
            base64:true,
            quality:1.0
          });

          if(!pickerResult.cancelled){
            //this.setState({userImage: pickerResult.uri, imageResult : pickerResult, imageSelected: true});
            this.uploadImage(pickerResult.uri,'front-image')
            .then(()=>{
                alert('success');
            })
            .catch((error)=>{
                alert(error)
            });
        }
      }

 uploadImage = async(uri,imageName) => {

    const response = await fetch(uri);
    const blob =await response.blob();

    var ref = fire.storage().ref().child('images/'+imageName);
    return ref.put(blob);
}

//render method is here
                   <TouchableOpacity onPress={this._pickImageFront}>

                        <Image
                        source={ImageIcon}
                        style={{width:wp('10%'),
                        height:hp('5%')}}/>
                    </TouchableOpacity>

0 个答案:

没有答案