react-native-documents / document-picker

Document Picker for React Native
https://react-native-documents.github.io/
MIT License
1.35k stars 437 forks source link

type: types.pdf does not limit the selection #706

Open LJW123 opened 6 months ago

LJW123 commented 6 months ago

Although I set it to PDF, I can still select files of any format. However, if I set it to images, only photos can be selected.

DocumentPicker.pick({ allowMultiSelection: false, presentationStyle: 'fullScreen', type: types.pdf, copyTo: 'documentDirectory', })

LJW123 commented 6 months ago

android 13

vonovak commented 6 months ago

Hello and thanks for reporting, can you share a video? What document provider did you use to select documents?

Thank you 🙂

LJW123 commented 6 months ago

Thank you, I understand now;

it's a problem with the document provider. When I use a Xiaomi phone (Android 13) and choose files using the system's file manager, I can only select PDFs. However, when I use a document provider from another app (like QQ, a popular instant messaging app in China), I can select files of any type. When using a Huawei phone (HarmonyOS 2.0.1, and I cannot see the supported Android version), all document providers (including the system's own) allow me to select files of any format.

https://github.com/react-native-documents/document-picker/assets/18021287/5340c4fb-3daf-4d22-a885-e5d35a6c3693

LJW123 commented 6 months ago

Is there no solution to this issue? Since third-party document providers do not restrict file types, there's nothing we can do. If it's unsolvable, can I limit which document providers can be used? For example, can I restrict users to only select files from the system's document provider and not from third-party document providers?

vonovak commented 6 months ago

Hello, I'm sorry you have this issue but I don't think there's a way to fix it. The only thing you can do is handle this situation inside of your application and display an error in this case. You can use the hasRequestedType field in the response (only available in the module for sponsors), see docs