11

Hello guys I guess some of you already got in this issue. I am wonder if there is a way to select multiple files using Expo Document Picker or I just need to select them one by one which obviously is not a good way for the user.

For now all I have is this

_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.!`
      });
    }
  };
Markus Hayner
  • 2,869
  • 2
  • 28
  • 60

1 Answers1

0

As the expo documentation state : “multiple (boolean) -- (Web Only) Allows multiple files to be selected from the system UI. Defaults to false.”

I’ve corrected your code :


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

Francky Vincent
  • 453
  • 4
  • 12