0

I have the web page, that renders an array of downloadable pdf files. Something like this: enter image description here In the browser I had a URL, that looked like this:

https://www.wmata.com/schedules/maps/upload/2019-System-Map.pdf

And I can easily download this URL. In the webview I have the following URL after tapping:

blob:https://mydomain/7bc4fe9c-3405-4a86-bde2-944e1f15174d

I read lots of stuff where people recommend using js code to download blob files. Like this one or here is solution for flutter

So, my js script looks like this:

var xhr = new XMLHttpRequest();
var blobUrl = "blobUrlPlaceholder";
console.log(blobUrl);
xhr.open('GET', blobUrl, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
  if (this.status == 200) {
    var blob = this.response;
    var reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = function() {
      var base64data = reader.result;
      var base64ContentArray = base64data.split(",");
      var mimeType = base64ContentArray[0].match(/[^:\s*]\w+\/[\w-+\d.]+(?=[;| ])/)[0];
      var decodedFile = base64ContentArray[1];
      console.log(mimeType);
      window.flutter_inappwebview.callHandler('blobToBase64Handler', decodedFile, mimeType);
    };
  };
};
xhr.send();

As a result, I get HTML page with this text: text

So, my questions are the following:

  1. Can I reflect files on the webview as the web browser does? I mean files with the pdf extension, not as blob ones?
  2. I guess I missed something put into the request in the js code, but how to know what should I additionally add? Why does the browser know it and the webview - does not?

I've also tested Chrome custom tabs, which work perfectly, but I must use Webview. I tried webview_flutter and flutter_inappwebview in the Flutter and native Android webview, but no success. Thanks in advance for any help.

Roman Soviak
  • 791
  • 2
  • 9
  • 30
  • Why is the html source in the WebView different from the one 'in the browser'? And what do you mean with 'after tapping'? – blackapps Apr 08 '23 at 09:44
  • `Can I reflect files on the webview as the web browser does?` ? What do you mean with reflect? – blackapps Apr 08 '23 at 09:46
  • @blackapps I don't know why webview doesn't act like a browser. After tapping on icon I downloading file and url is different on the browser and webview – Roman Soviak Apr 08 '23 at 10:16
  • On the webview I have blob:.... on the browser I have correct url with pdf. When I downloaded blob I had error – Roman Soviak Apr 08 '23 at 10:19
  • I asked you why you have a different one on the webview. Which icon? Start with the html source. Post it here. Is it different? I asked it! And you explained nothing about 'reflect'. – blackapps Apr 08 '23 at 10:45
  • @blackapps on the first screenshot we have download icon and after tapping on this icon we trigger url. In the browser this url looks like I wrote in the question with the .pdf extension and in the webview it is blob file. By using word reflect I meant, how to create pdf urls in the webview, how browser does. Browser did it automatically and web view - no – Roman Soviak Apr 08 '23 at 11:03
  • Please show html source. Third time i ask. A webview will not convert https to blob so lets see where this blob comes from. – blackapps Apr 08 '23 at 11:14

0 Answers0