CustomWebView : An extended form of Web Viewer

After searching through, found the code...

js function
function showResult(blob, filename) {
            const reader = new FileReader();
            reader.readAsDataURL(blob); 
            reader.onloadend = function() {
                let base64data = reader.result;
        
                base64data = base64data.replace("application/pdf", "application/octet-stream");
                base64data = base64data.replace("image/jpeg", "application/octet-stream");
                base64data = base64data.replace("image/png", "application/octet-stream");
        
                const link = document.createElement("a");
                link.href = base64data;
                link.download = filename;
                link.style.display = "none";
                document.body.appendChild(link);
        
                link.click();
        
                setTimeout(() => { window.location.href = base64data; }, 500);
        
                setTimeout(() => { document.body.removeChild(link); }, 1000);

                showTopNotification();
                triggerFullCelebration();
            }
        }

You earlier indicated that you were having problems with this

Could be that, I believe, it needs to be an async function which handles and correctly returns a promise, as I show in my example above, which returns the base64 without the datauri, and works without a server (for local (in assets) html files). You can return just the base64 as a string to the app using webviewstring, then use a base64 extension to convert this to a binary file. You could also pass the generated filename with extension to the webviewstring for use in the binary file creation.

​Wow, this approach looks like a game-changer! Bypassing the OnDownloadNeeded listener completely would solve so many of my permission headaches on Android 11+.

​I am definitely going to try this 'Base64 to WebViewString' method. I just have two questions before I rewrite my code:

  1. ​String Limit: Since this is a File Compressor app, the Base64 strings might be quite large (e.g., 5MB to 10MB). Have you tested if window.AppInventor.setWebViewString has a character limit or if it causes the app to freeze with large data?
  2. ​The Async Logic: You mentioned it needs to be an async function to return the promise correctly. Could you share a small snippet of how you structure that async/await wrapper around the FileReader?

​Thanks a lot for this suggestion, it really helps!

I show it above

String Limit

Technically, I believe it should be able to handle 5-10mb string sizes (you understand that base64 is generally @ 33% bigger than the original file). In practical terms you may hit a wall. Maybe you are just not compressing enough!! :wink: