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

Mar*_*ner 7 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.!`
      });
    }
  };
Run Code Online (Sandbox Code Playgroud)

Fra*_*ent 1

正如博览会文档所述:\xe2\x80\x9cmultiple(布尔值)--(仅限 Web)允许从系统 UI 中选择多个文件。默认为 false。\xe2\x80\x9d

\n

我\xe2\x80\x99已经更正了你的代码:

\n
\nconst picked = await DocumentPicker.getDocumentAsync({\n        type: "*/*",\n        multiple: true,\n        copyToCacheDirectory: true\n      });\n\n
Run Code Online (Sandbox Code Playgroud)\n