react-native - 如何在 Expo 中使用 DocumentPicker 选择多个文件?
问题描述
大家好,我想你们中的一些人已经参与了这个问题。我想知道是否有一种方法可以使用 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.!`
});
}
};
解决方案
正如博览会文档状态:“多个(布尔值)-(仅限 Web)允许从系统 UI 中选择多个文件。默认为 false。”</p>
我已经更正了您的代码:
const picked = await DocumentPicker.getDocumentAsync({
type: "*/*",
multiple: true,
copyToCacheDirectory: true
});