react-native-documents / document-picker

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

fix: .CSV files cannot be selected on Android using the type csv #695

Open roge530 opened 6 months ago

roge530 commented 6 months ago

Resolve the issue on Android where .csv files cannot be selected On /src/fileTypes.ts on line 4 the current version on master says: csv: 'text/csv',

and I replace for:

csv: 'text/comma-separated-values',

With this change is possible to read csv files on Android as it should be expected. This works because when reading a .csv file using allFiles then accessing to the "type" property it returns "text/comma-separated-values".

For testing I provide this screenshots

Before the fix

image

Here I show the screen where the user is suppose to select a csv file

image

Here the user sees the file explorer, in this case the Downloads folder where I have a csv file, the csv file is display on the right window of vscode for reference of the content. We can see is a valid csv file but the code on the center window using

const res: DocumentPickerResponse = await DocumentPicker.pickSingle({ type: [DocumentPicker.types.csv], });

Does not allows use to pick the csv file

After the fix

image

With the fix the csv file is allowed to be picked

image

As we see, the file is read properly and can be used on the app

This should only apply to android devices, the emulator uses API 33, Android 13.0 Tiramisu

image

I run yarn typescript with 0 issues

image

Here is the differences between my branch and main

vonovak commented 5 months ago

Hello, thank you for the PR. Can you share a little more information about what android you tested this with?

I think if we just merge this change, it will work better for some people, but it will stop working for some other people, so I'd like to find something that works for everyone. Thank you 🙂

roge530 commented 5 months ago

Of course, on the next days I will upload some test with different versions of android, can you provide me with a range?

vonovak commented 5 months ago

Well, the more the better 🙂😄. But I was also wondering what device you have experienced the issue with, I'm curious. Thank you! 🙂

roge530 commented 5 months ago

Here are the details of the device

image

I´ve been bussy lately, I´m sorry for taking this long to answer

vonovak commented 4 months ago

hello @roge530 and thank you for your patience, could you make the changes so that mimeTypes.csv actually maps to both text/csv and also text/comma-separated-values?

I guess one way to do it is to allow for mimeTypes to be a string, but also array of strings, and in this case the value would be ['text/csv', 'text/comma-separated-values']. Does that make sense?

The first value is the "standard" one but apparently google uses text/comma-separated-values. We should use both to make sure it works with both cases.

Thank you!