Android 反应本机图像上载不上载图像

Android 反应本机图像上载不上载图像,android,react-native,firebase-storage,image-uploading,Android,React Native,Firebase Storage,Image Uploading,我正在开发一个包含图像上传程序的应用程序。我在网上找到了一些可以上传图片的代码。而且它起了部分作用。这意味着当我按下“选择图像”按钮时,它会打开gallery,我可以选择并裁剪图像。当我选择“确定”时,在裁剪之后什么也不会发生。它只显示图像,不上传到firebase云。这是我的密码 import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, Button,

我正在开发一个包含图像上传程序的应用程序。我在网上找到了一些可以上传图片的代码。而且它起了部分作用。这意味着当我按下“选择图像”按钮时,它会打开gallery,我可以选择并裁剪图像。当我选择“确定”时,在裁剪之后什么也不会发生。它只显示图像,不上传到firebase云。这是我的密码

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button,
  Image,
  ActivityIndicator,
  TouchableOpacity
} from 'react-native';
import * as firebase from 'firebase';
import RNFetchBlob from 'react-native-fetch-blob';
import ImagePicker from 'react-native-image-crop-picker';
export default class RNF extends Component {
  constructor (props) {
    super(props);
    this.state = {
      loading: false,
      dp: null
    };
  }
  openPicker () {
    this.setState({ loading: true });
    const Blob = RNFetchBlob.polyfill.Blob;
    const fs = RNFetchBlob.fs;
    window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
    window.Blob = Blob;
    // const { uid } = this.state.user
    const uid = '12345';
    ImagePicker.openPicker({
      width: 300,
      height: 300,
      cropping: true,
      mediaType: 'photo'
    }).then(image => {
      const imagePath = image.path;

      let uploadBlob = null;

      const imageRef = firebase.storage().ref(uid).child('dp.jpg');
      let mime = 'image/jpg';
      fs.readFile(imagePath, 'base64')
        .then((data) => {
          // console.log(data);
          return Blob.build(data, { type: `${mime};BASE64` });
        })
        .then((blob) => {
          uploadBlob = blob;
          return imageRef.put(blob, { contentType: mime });
        })
        .then(() => {
          uploadBlob.close();
          return imageRef.getDownloadURL();
        })
        .then((url) => {
          let userData = {};
          // userData[dpNo] = url
          // firebase.database().ref('users').child(uid).update({ ...userData})

          let obj = {};
          obj['loading'] = false;
          obj['dp'] = url;
          this.setState(obj);
        })
        .catch((error) => {
          console.log(error);
        });
    })
      .catch((error) => {
        console.log(error);
      });
  }
  render () {
    const dpr = this.state.dp ? (<TouchableOpacity onPress={ () => this.openPicker() }><Image
      style={{ width: 100, height: 100, margin: 5 }}
      source={{ uri: this.state.dp }}
    /></TouchableOpacity>) : (<Button
      onPress={ () => this.openPicker() }
      title={ 'Change Picture' }
    />);

    const dps = this.state.loading ? <ActivityIndicator animating={this.state.loading} /> : (<View style={styles.container}>
      <View style={{ flexDirection: 'row' }}>
        { dpr }
      </View>
    </View>);

    return (
      <View style={styles.container}>
        { dps }
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5
  }
});

AppRegistry.registerComponent('RNF', () => RNF);