0

正如标题所说,我正在尝试以 react native 将图像上传到 firebase。我正在为此使用react-native-image-pickerfirebase模块。我的代码如下:(为清楚起见,仅包括“主要”部分)

import ImagePicker from 'react-native-image-picker';
...
//called on pressing a button
onChooseImagePress = async () => {
    let result = await ImagePicker.open({     //error occurs here
        takePhoto: true,
        useLastPhoto: true,
        chooseFromLibrary: true
    });
    if (!result.cancelled) {
        this.uploadImage(result.uri, "test-image")
        .then(() => {
            Alert.alert("Success");
        })
        .catch((error) => {
            Alert.alert(error);
        });
    }        
}

uploadImage = async (uri, imageName) => {
    const response = await fetch(uri);
    const blob = await response.blob();

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

问题:

我收到此错误:undefined is not a function。这是相同的屏幕截图:

在此处输入图像描述

我不确定它甚至意味着什么,因为它ImagePicker有一个open功能。请注意,我已经提供了所需的权限。因此,这不是问题。请帮我解决这个问题。谢谢...

4

1 回答 1

1

你在用React-native ImagePicker吗?API文档中没有open

API参考react-native-image-picker

这是获取所需所选图像值的默认示例。

import ImagePicker from 'react-native-image-picker';

// More info on all the options is below in the API Reference... just some common use cases shown here
const options = {
  title: 'Select Avatar',
  customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
  storageOptions: {
    skipBackup: true,
    path: 'images',
  },
};

/**
 * The first arg is the options object for customization (it can also be null or omitted for default options),
 * The second arg is the callback which sends object: response (more info in the API Reference)
 */
ImagePicker.launchImageLibrary(options, (response) => {
  console.log('Response = ', response);

  if (response.didCancel) {
    console.log('User cancelled image picker');
  } else if (response.error) {
    console.log('ImagePicker Error: ', response.error);
  } else if (response.customButton) {
    console.log('User tapped custom button: ', response.customButton);
  } else {
    const source = { uri: response.uri };

    // You can also display the image using data:
    // const source = { uri: 'data:image/jpeg;base64,' + response.data };

    this.setState({
      avatarSource: source,
    });
  }
});
于 2019-08-03T16:08:38.703 回答