I have the web page, that renders an array of downloadable pdf files. Something like this:
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:
So, my questions are the following:
- Can I reflect files on the webview as the web browser does? I mean files with the pdf extension, not as blob ones?
- 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.