Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 请用户使用react native按钮从照片库或照相机中选择照片_Reactjs_React Native - Fatal编程技术网

Reactjs 请用户使用react native按钮从照片库或照相机中选择照片

Reactjs 请用户使用react native按钮从照片库或照相机中选择照片,reactjs,react-native,Reactjs,React Native,我正在使用expo,无法使用,我想知道如何实现相同的功能。我为每个选项分别提供了以下代码(一个按钮用于gallery,另一个按钮用于camera) 另一个是 uploadImage = async() =>{ // Display the camera to the user and wait for them to take a photo or to cancel // the action let result = await ImagePicker.laun

我正在使用expo,无法使用,我想知道如何实现相同的功能。我为每个选项分别提供了以下代码(一个按钮用于gallery,另一个按钮用于camera)

另一个是

uploadImage = async() =>{

       // Display the camera to the user and wait for them to take a photo or to cancel
  // the action
  let result = await ImagePicker.launchCameraAsync({
          allowsEditing: true,
          aspect: [4, 3],
        });

        if (result.cancelled) {
          return;
        }

        // ImagePicker saves the taken photo to disk and returns a local URI to it
        let localUri = result.uri;
        let filename = localUri.split('/').pop();

        // Infer the type of the image
        let match = /\.(\w+)$/.exec(filename);
        let type = match ? `image/${match[1]}` : `image`;

        // Upload the image using the fetch and FormData APIs
        let formData = new FormData();
        // Assume "photo" is the name of the form field the server expects
        formData.append('photo', { uri: localUri, name: filename, type });

        return await fetch(YOUR_SERVER_URL, {
          method: 'POST',
          body: formData,
          header: {
            'content-type': 'multipart/form-data',
          },
        });
}


}
这两个函数被称为

 <Button title="Pick image" onPress={this._pickImage} />
 <Button title="Upload image" onPress={this._uploadImage} />


但是,我如何使我的工作如下所示:

世博会已经发布了库,它提供了您所需的确切功能

你需要在答案中发布相关代码,而不仅仅是链接
 <Button title="Pick image" onPress={this._pickImage} />
 <Button title="Upload image" onPress={this._uploadImage} />