skip to Main Content

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


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

    Login or Signup to reply.
  2. 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 the rn-fetch-blob package or you will be able to render it based on what your URL provides. If it is an attachment 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.

    Login or Signup to reply.
  3. This might be helpful:

        <WebView
            onFileDownload={({ nativeEvent: { downloadUrl } }) => {
                if (downloadUrl) {
                    Linking.openURL(downloadUrl)
                }
            }}
        />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search