Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native: images with space in name won't load in IOS (device, not https issue)

Images with spaces in their name won't load in IOS, for android it worked by replacing the spaces with %20, but this solution didn't work on ios. React native.

I m loading the images remotely using uri, in a normal Image container. images without space load fine.

like image 688
Kensoftware Avatar asked Dec 29 '17 22:12

Kensoftware


2 Answers

<Image source={{uri: fileName.replace(/ /g, '%20')}} style={styles.image} />

works on [email protected]

like image 162
Sandy Avatar answered Oct 22 '22 04:10

Sandy


encodeURI("http://www.yourdomain.tld/sample image.jpg")

Output

http://www.yourdomain.tld/sample image.jpg

to

http://www.yourdomain.tld/sample%20image.jpg

Usage

<Image source={{uri: encodeURI(fileUri)}} />

the best way is to use the js builtin javascript function encodeURI

because we also have to convert some special characters in URLs

like image 45
Muhammad Numan Avatar answered Oct 22 '22 05:10

Muhammad Numan