[iOS] Permission Denied trying to access a file with spaces in the filename
v. 2.1.0 React Native 0.57.8
I've seen similar issues reported here when trying to get a file with certain characters. In my case, it's a space. If the file name has a space, the uri will show it as %20. Then, when attempting to access the file path later. Even if I decode the uri I get the same error. This does not happen in Android, and it does not happen when file names don't have spaces.
Upgrading to react-native-document-picker 2.3 or 3.0 led to issues in Android. 3.0 threw an error about combining gradle and non-gradle in the same project.
I worked around this by decoding the URI in iOS only (see related issue here).
also reported in https://github.com/rnmods/react-native-document-picker/issues/13 https://github.com/rnmods/react-native-document-picker/issues/291 and https://github.com/rnmods/react-native-document-picker/issues/350, which are all closed for some reason, seems like a bug that we need to use decode uri for the file path to be correct?
seems might be due to https://github.com/rnmods/react-native-document-picker/blob/e821f51b0340661bd61debfc921be0cba9c35803/ios/RNDocumentPicker.m#L106
this seems to fix it for me, fileCopyUri goes from file:///..../file%20name.pdf to /..../file name.pdf and works without other modifications to view the file using react-native-pdf.
- [result setValue:maybeFileCopyPath.absoluteString forKey:FIELD_FILE_COPY_URI];
+ [result setValue:maybeFileCopyPath.path forKey:FIELD_FILE_COPY_URI];
Maybe related to the other reports about needing to trim file:// too?...
hello and thanks for reporting. What you likely need to do is remove the file:// prefix and then decode the path so that you dont have eg. %20 instead of .
Hope this helps, thank you! :)