document-picker icon indicating copy to clipboard operation
document-picker copied to clipboard

[iOS] Permission Denied trying to access a file with spaces in the filename

Open jayporta opened this issue 7 years ago • 4 comments

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.

jayporta avatar Apr 11 '19 14:04 jayporta

I worked around this by decoding the URI in iOS only (see related issue here).

hednowley avatar May 17 '19 13:05 hednowley

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?

scrungrth avatar Sep 16 '21 21:09 scrungrth

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?...

scrungrth avatar Sep 16 '21 22:09 scrungrth

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! :)

vonovak avatar Oct 02 '21 19:10 vonovak