Can't read file names with : on React Native

Solution 1:

Have you tried using '\' (backslash)?

Please let me know if this works.

var str = "file:///storage/emulated/0/somwhere/foo foo Nov 21, 2018 12:16:04 PM.pdf";
    var result = str.split(" ").join("\ "); // added '\'
    console.log('Result',result);

Snippet copied from answer provided by Vishal Vaghasiya

Solution 2:

I wasn't able to explain the whole process of the app.

The return from database has something like this

{file: "//storage/emulated/0/somwhere/foo foo Nov 21, 2018 12:16:04 PM.pdf"}

which I use to read with my PDF library. However the actual file that is stored locally has a name of foo foo Nov 21, 2018 121604 PM.pdf

so I have to do this instead

'file://' + file.replace(/:/g, "")

or it can be done like this

'file://' + file.replace(/[|&:;$%@"<>()+,]/g, "")