大家好,我想你们中的一些人已经遇到了这个问题。我想知道是否有一种方法可以使用 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.!`
});
}
};
最佳答案
正如世博会文档所述:“multiple (boolean) -- (Web Only) 允许从系统 UI 中选择多个文件。默认为假。”
我已经更正了你的代码:
const picked = await DocumentPicker.getDocumentAsync({
type: "*/*",
multiple: true,
copyToCacheDirectory: true
});
关于react-native - 如何在 Expo 中使用 DocumentPicker 选择多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56114889/