我试图限制可以由 Expo.DocumentPicker.getDocumentAsync 选择的文件类型,但没有成功。
如何一次过滤多个 mimeType?
我已经尝试如下:
Expo.DocumentPicker.getDocumentAsync({type: "image/*;application/pdf"});
和
Expo.DocumentPicker.getDocumentAsync({type: "image/*,application/pdf"});
和
Expo.DocumentPicker.getDocumentAsync({type: ["image/*","application/pdf"]}); //CRASH
我正在使用 sdk 27.0.0。
一些建议?世博队? :}
引用:
https://docs.expo.io/versions/latest/sdk/document-picker#type-string----the-mime-type-of
最佳答案
目前,我们似乎无法在 expo 的文档选择器上传递多个 mime 类型,因为它是字符串类型而不是数组。还有一个关于相同的未决问题 here
我尝试使用以下任何一种 MIME 类型来实现与此类似的仅上传某些文件类型:
let result = await DocumentPicker.getDocumentAsync({
type: "*/*" // all files
// type: "image/*" // all images files
// type: "audio/*" // all audio files
// type: "application/*" // for pdf, doc and docx
// type: "application/pdf" // .pdf
// type: "application/msword" // .doc
// type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" // .docx
// type: "vnd.ms-excel" // .xls
// type: "vnd.openxmlformats-officedocument.spreadsheetml.sheet" // .xlsx
// type: "text/csv" // .csv
});
对于其他 MIME 类型,请查看 this
关于react-native - 如何正确使用 Expo.DocumentPicker.getDocumentAsync。 [博览会] [ReactNative],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50108496/