here you can see the web view component. When the page load clicking on href tag file needs to download in android
<WebView
ref={webViewRef}
style={styles.webv}
source={{
uri: {{Domain_URL}},
}}
onMessage={onWebViewMessage}
onError={onWebViewError}
onLoadStart={onWebViewLoadStart}
onLoad={onWebViewLoadEnd}
javaScriptEnabled
domStorageEnabled
setBuiltInZoomControls={false}
/>
3
Answers
I think you should change the logic without using webview. In native languages(Swift/Java), WebView has similar issues, This means we couldn’t implement the feature with react-native-webview,
So please try with rn-fetch-blob.
I want to suggest you "rn-fetch-blob" to download the file, and store it on android file system using "fs".
Maybe you can get the local url in file system.
Then, load the file on webview with the above local url.
I would like to mention here that please check your Content-Disposition response header value. If it is
inline
then it won’t be downloaded, you will have to do it manually using thern-fetch-blob
package or you will be able to render it based on what your URL provides. If it is anattachment
then the react-native-webview will automatically download it for you without any extra code.The above behavior works differently for iOS as it doesn’t handle the Content-Disposition header so all file formats will be rendered in iOS Webview without downloading, unlike Android.
This might be helpful: