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

Downloading a URI starting with blob:http://... on android crashes the app #295

Closed
chaudhryjunaid opened this issue Jan 31, 2019 · 33 comments
Labels
Stale User: minimal repro Need to publish a minimal app demonstrating this behavior

Comments

@chaudhryjunaid
Copy link

I have a webview on Android that attempts to download an embedded pdf file via a blob URL. However, the app crashes on such attempt.

@jamonholmgren
Copy link
Member

Hi @chaudhryjunaid , can you provide a minimal reproduceable repo so we can see this happening?

@jamonholmgren jamonholmgren added the User: minimal repro Need to publish a minimal app demonstrating this behavior label Jan 31, 2019
@chaudhryjunaid
Copy link
Author

@jamonholmgren will try to build one over the weekend if I get the time.

@marexv
Copy link

marexv commented Feb 22, 2019

I have the same issue. Need some help with that repo @chaudhryjunaid?

Here is my crashalytics stack trace:

RNCWebViewManager.java line 464
com.reactnativecommunity.webview.RNCWebViewManager$3.onDownloadStart

Fatal Exception: java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: blob:https://myurlwashere.com/4514c839-82f7-4a9c-ac32-6f367fbdb624
       at android.app.DownloadManager$Request.<init>(DownloadManager.java:613)
       at 
com.reactnativecommunity.webview.RNCWebViewManager$3.onDownloadStart(RNCWebViewManager.java:464)
       at xH.a(SourceFile:510)
       at ayK.handleMessage(SourceFile:25)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6938)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

@moughxyz
Copy link

moughxyz commented May 8, 2019

On iOS, navigating to a blob via window.location.href = blobUrl will show the file within the webview, but I haven't found a way to get the file to actually download and save to the user's photos or files. (Using the method to create a temporary a tag and and then a.click() has no effect.)

This answer has a workaround, although not too elegant:
https://stackoverflow.com/questions/45065085/how-to-read-a-blob-data-url-in-wkwebview

In case you want to test this, you can create a blob link in JS with this:

 downloadData(reactNative = false) {
    var link = document.createElement('a');
    link.setAttribute('download', "foo.json");
    var url = window.URL.createObjectURL(new Blob([JSON.stringify({foo: "bar"})], {type: 'text/json'}));
    link.href = url;
    if(reactNative) {
      window.location.href = link.href;
    } else {
      document.body.appendChild(link);
      link.click();
      link.remove();
    }
  }

reactNative is to handle if we're in RN, since link.click() has no effect.

@nyalsadiq
Copy link

I'm having the same problem, any update on this?

@memelie
Copy link

memelie commented Jun 11, 2019

I am facing the same issue! @jamonholmgren any help?

@JesperBry
Copy link

I'm facing the same issue, any update on this?
I've noticed that files represented as a blob, don't get a path and the app crashes. However it works with image-files represented as blobs, but not with pdf's.

@fvidalarcon
Copy link

fvidalarcon commented Jul 19, 2019

I join the post, I am facing the same problem...

java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: blob:

@Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.allowScanningByMediaScanner(); request.setMimeType(mimetype);

@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

@github-actions github-actions bot added the Stale label Sep 18, 2019
@aszenz
Copy link

aszenz commented Sep 18, 2019

@jamonholmgren

Here's an example to reproduce it:

import React from 'react'
import { View } from 'react-native'
import { WebView } from 'react-native-webview'

const App = () => {
  return (
    <View style={{ flex: 1 }}>
      <WebView
        source={{
          uri: 'https://codepen.io/vidhill/pen/bNPEmX'
        }}
        javaScriptEnabled
        allowFileAccess
        mixedContentMode={'always'}
        domStorageEnabled
        textZoom={150}
      />
    </View>
  )
}

export default App;

The embedded codepen url has a link (Download JSON) which should download a json file, but the app crashes on clicking the link.

@daniily000
Copy link

Same problem. Any news?

@bbuttam
Copy link

bbuttam commented Dec 15, 2019

I'm having the same problem, any update on this?

@DaniGo-1
Copy link

DaniGo-1 commented Jan 9, 2020

¿Alguien encontró alguna solución?

@razaadeel
Copy link

Facing the same issue. Anyone found the solution?

@safaiyeh safaiyeh reopened this Jan 16, 2020
@safaiyeh safaiyeh removed the Stale label Jan 16, 2020
@jack-salvona-dynasty
Copy link

Also currently facing this issue, with PDF, Excel & CSV blob downloads

@bpfeiffer187
Copy link

I am also facing this same issue. Anyone have an anticipated date for a fix?

@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

@bendadaniel
Copy link

+1

@donysukardi
Copy link

Still searching for solutions

@jamonholmgren jamonholmgren reopened this Jun 13, 2020
@jamonholmgren
Copy link
Member

Thanks to @aszenz for the minimal repro. If someone wants to tackle fixing this problem, I'm happy to review the PR!

@lamendaviesa
Copy link

lamendaviesa commented Jun 17, 2020

Hi! @jamonholmgren @aszenz probe to do that.

<WebView
allowFileAccess
originWhitelist={['https://', 'blob:']}
javaScriptEnabled
source={{
uri: 'https://codepen.io/vidhill/pen/bNPEmX'
}}
/>

It works in iOS, I have problems in Android.

Error Android:
java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: blob:https://familiados.com/65829a53-1c51-4369-96da-61ff6d8f3094
at android.app.DownloadManager$Request.(DownloadManager.java:459)
at com.reactnativecommunity.webview.RNCWebViewManager$2.onDownloadStart(RNCWebViewManager.java:205)
at ic.a(PG:548)

@aszenz
Copy link

aszenz commented Jun 17, 2020

@lamendaviesa
The problem is not specific to this package, instead the Android Download Manager only accepts http and https download uris.
So blob uris needs to be converted into a base64 string in JS and then that base64 string has to be written on the download path using Android Java APIs.

@lamendaviesa
Copy link

@aszenz Thanks!

@KA-32
Copy link

KA-32 commented Oct 16, 2020

why is this issue closed ?

@SamiChab
Copy link

Still looking for an answer to this... Can someone help?

@adiXcodr
Copy link

Could anybody find a solution?

@shivammaindola
Copy link

Has anybody got the solution?

@Cosmonaut191
Copy link

Any leads?

@gogul-ct
Copy link

Any solution?

@BassamRazzaq100
Copy link

I have the same problem unable to download pdf file.
After alot of search. I figure out that website is use the following code script to get the downloaded data.
columns: [
{data: 'id', name: 'id'},
{data: 'patient_name', name: 'patient_name'},
{data: 'email', name: 'email'},
{data: 'phone', name: 'phone'},
{data: 'consultation_type', name: 'consultation_type'},
{data: 'category', name: 'category'},
{data: 'address', name: 'address'},
{data: 'state', name: 'state'},
{data: 'date', name: 'date'},
]

@eshernandez
Copy link

Any solution?

@Vitor-Conti
Copy link

Any Updates? Why is this closed!

@fukemy
Copy link

fukemy commented Jan 31, 2024

any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale User: minimal repro Need to publish a minimal app demonstrating this behavior
Projects
None yet
Development

No branches or pull requests