Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webview is not download automatically. Both ios and android #2858

Closed
atjab opened this issue Feb 16, 2023 · 4 comments
Closed

Webview is not download automatically. Both ios and android #2858

atjab opened this issue Feb 16, 2023 · 4 comments
Labels

Comments

@atjab
Copy link

atjab commented Feb 16, 2023

The webview not download file automatically to device. In html, I use a link tag and set attribute as download. In webview ios, just open and preview that file but not download automatically. At the same time, android nothing happened and reload page. I should fix in web script for download or it possible to setting or something in native app via webview ?

"react-native": "0.70.6",
"react-native-webview": "^11.26.0",

<Webview
    javaScriptEnabled={true}
    domStorageEnabled={true}
    allowFileAccessFromFileURLs={true}
    allowUniversalAccessFromFileURLs={true}
    allowFileAccess={true}
    originWhitelist={['*']}
    mixedContentMode={'always'} 
/>

In my web script

const downloadFileFromObjectUrl = (source, filename) => {
    const downloadUrl = window.URL.createObjectURL(source)
    const link = document.createElement('a')
    link.href = downloadUrl
    link.setAttribute('download', filename)
    document.body.appendChild(link)
    link.click()
    link.remove()
}

Thank everyone for suggestion.

@atjab atjab changed the title How to auto download file on ios and android Webview is not download automatically. Both ios and android Feb 16, 2023
@TheAlmightyBob
Copy link
Collaborator

For iOS, that is the expected behavior. You'd need to implement onFileDownload

For Android, that's not necessarily expected, but we'd need a sample project or Expo Snack that repros the issue. (or you could debug the Android code yourself, if you search for "download" it shouldn't be hard to find places to put a breakpoint)

@BraveEvidence
Copy link

@github-actions
Copy link

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

@linonetwo
Copy link

linonetwo commented Mar 7, 2024

I can confirm Android is not downloading when click a link like

var link = document.createElement("a");
var blob = new Blob(["sdfa"], {type: "text/html"});
link.setAttribute("href", URL.createObjectURL(blob));
link.setAttribute("download","filename");
document.body.appendChild(link);
// <a href=​"blob:​http:​/​/​localhost/​cf8ae139-a28c-43ec-9943-86ff2e0d10d0" download=​"filename">​</a>​

link.click();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants