如何在Expo中使用DocumentPicker选择多个文件?

时间:2019-05-13 14:54:03

标签: react-native expo

大家好,我想你们中有些人已经遇到了这个问题。我想知道是否有一种使用Expo Document Picker选择多个文件的方法,或者我只需要一个一个地选择它们,这显然对用户来说不是一个好方法。

现在我只有这个

_selectAndUpload = async document => {
    try {
      const picked = await DocumentPicker.getDocumentAsync({
        type: "*/*",
        copyToCacheDirectory: true
      });
      if (picked.type === "cancel") {
        return;
      } else if (picked.type === "success") {
        const { name } = picked;
        const fileUri = `${FileSystem.documentDirectory}${name}`;
        if (Platform.OS === "ios") {
          const pickerResult = await FileSystem.downloadAsync(
            picked.uri,
            fileUri
          );
          this.handleDocumentPicked(pickerResult, document);
        } else {
          const pickerResult = {
            name: picked.name,
            uri: picked.uri
          };
          this.handleDocumentPicked(pickerResult, document);
        }
      } else {
        return;
      }
    } catch (error) {
      this.setState({
        success: false,
        successModVisible: true,
        successLineText: `We can't support this file.!`
      });
    }
  };

1 个答案:

答案 0 :(得分:0)

作为博览会文档状态:“多个(布尔)-(仅Web)允许从系统UI中选择多个文件。默认为false。”

我已更正您的代码:


const picked = await DocumentPicker.getDocumentAsync({
        type: "*/*",
        multiple: true,
        copyToCacheDirectory: true
      });