1

Is there a way we can download blob URL? I referred to the answer mentioned in this thread, but it didn't work for me.

Code is almost the same as the reference I mentioned above.

InAppWebView(
    initialOptions: options,
    initialUrlRequest: URLRequest(
      url: Uri.parse("https://someurl..."),
    ),
    onWebViewCreated: (InAppWebViewController controller) {
      elmsController.webViewController = controller;

      controller.addJavaScriptHandler(
        handlerName: 'blobToBase64Handler',
        callback: (data) async {
          if (data.isNotEmpty) {
            print('base64: $data');

            final String receivedFileInBase64 = data[0];
            final String receivedMimeType = data[1];

            final String yourExtension = 'pdf';

            createFileFromBase64(
                receivedFileInBase64, 'fileName', yourExtension);
          }
        },
      );
    },
    onReceivedServerTrustAuthRequest: (controller, challenge) async {
      return ServerTrustAuthResponse(
          action: ServerTrustAuthResponseAction.PROCEED);
    },

    onDownloadStart: (controller, url) async {
      var jsContent = await rootBundle.loadString("assets/base64.js");
      await controller.evaluateJavascript(
          source: jsContent.replaceAll("blobUrlPlaceholder", url.path));
    },
  ),


options = InAppWebViewGroupOptions(
    crossPlatform: InAppWebViewOptions(
        javaScriptEnabled: true,
        mediaPlaybackRequiresUserGesture: false,
        useOnDownloadStart: true),
    android: AndroidInAppWebViewOptions(
      useHybridComposition: true,
    ),
    ios: IOSInAppWebViewOptions(
      allowsInlineMediaPlayback: true,
    ));

Cannot see any errors too. The file is not downloaded.

Peiris
  • 115
  • 1
  • 3
  • 14
  • Can you show your code and pinpoint the line where there is an error with the expected behaviour? – Gpack May 31 '21 at 10:51
  • @Gpack There were no errors. I followed the same process as mentioned in the reference thread. – Peiris May 31 '21 at 18:48

1 Answers1

1

I wrote a solution for both Android and iOS to download blob in Flutter WebView. which may support any type of files.

Build a simple backend using Fluter with Jaguar or other backend framework Convert the blob as formData and post it to Flutter. The full code: https://github.com/guoguoguilai/flutter-webview-blob-download

PageGuo
  • 67
  • 4