[iOS] baseUrl not working. local image is not showing up.
See original GitHub issueBug description:
I use the code below to display a local image to Webview.
const imagePath = `${RNFS.DocumentDirectoryPath}/${new Date().toISOString()}.jpg`.replace(/:/g, '-');
const html = `<img src="${imagePath}" style="position: relative; max-width: 100%; max-height: 100%;"/>`;
<WebView
originWhitelist={['*']}
allowUniversalAccessFromFileURLs={true}
allowFileAccessFromFileURLs={true}
allowFileAccess={true}
source={{
html,
baseUrl: 'file://',
}}
/>
And it works perfectly on Android(emulator, device) and iOS(simulator). However, not work on iOS device.
the image exists. I can display it with the code below on RN.
<Image
style={{width: 250, height: 250,}}
source={{
uri: Platform.OS === 'ios' ?
imagePath
: `file://${imagePath}`,
}}
/>
To Reproduce: I couldn’t find
Expected behavior: the image is displayed on iOS device.
Screenshots/Videos:
Environment:
- react-native version: 0.61.5
- react-native-webview version: 8.0.4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:8
Top Results From Across the Web
[iOS] baseUrl not working. local image is not showing up.
I have found a solution for local images rendering in react-native-webview in iOS. convert the image in base64 then used it's working fine...
Read more >WKWebView fails to load images and CSS using ...
On the simulator all works well, but on acutal device the local images are not showing (also no ? or anything indicating an...
Read more >WKWebview loadHTMLString not load
Using UIWebView - everything works fine. Using WKWebView - extrenal files (css, images, js) are not loaded. Yes, I use correct baseURL.
Read more >The Document Base URL element - HTML - MDN Web Docs
If there is no parent, acts the same as _self . _top : Show the result in the topmost browsing context (the browsing...
Read more >URLs in Swift: Common scenarios explained in-depth
While working with URLs we often need to verify things like making ... get the base for a certain link if the URL...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have found a solution for local images rendering in react-native-webview in iOS. convert the image in base64 then used it’s working fine on all iOS devices.
const fs = RNFetchBlob.fs const imageData = await fs.readFile(
${imageLocalPath}
, ‘base64’) const htmlStr =<html><body><img src="data:image/png;base64,${imageData} ></body> </html>
return (<WebView originWhitelist={[‘*’]} source={{ htmlStr }} />)
The same issue facing with all latest version, I need community support and help to fix it.