gpt4 book ai didi

file - React Native 文件选择器

转载 作者:行者123 更新时间:2023-12-04 15:20:00 24 4
gpt4 key购买 nike

问题来了:我已经搜索过很多次,但我终其一生都找不到如何在 React Native 中显示文件选择器对话框。最接近的是图像选择器(第 3 方组件),但它是一个专用接口(interface),不允许我从 Android 的文件系统中选择任意文件。
有人知道,我该如何选择文件?

最佳答案

我正在使用这个包react-native-file-picker

  • 从 github 安装包

    npm 安装 https://github.com/Lichwa/react-native-file-picker --保存
  • 然后链接它:

    rnpm 链接 react-native-file-picker
  • 导入包

    var FilePickerManager = require('NativeModules').FilePickerManager;
  • 然后像这样使用它:
    const options = {
    title: 'File Picker',
    chooseFileButtonTitle: 'Choose File...'
    };

    FilePickerManager.showFilePicker(options, (response) => {
    console.log('Response = ', response);

    if (response.didCancel) {
    console.log('User cancelled photo picker');
    }
    else if (response.error) {
    console.log('ImagePickerManager Error: ', response.error);
    }
    else if (response.customButton) {
    console.log('User tapped custom button: ', response.customButton);
    }
    else {
    this.setState({
    file: response
    });
    }
    });
  • 关于file - React Native 文件选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36521755/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com