0

I need to download an image from a blob url.

I try using those solution, but none of them worked for me:

Flutter WebView blob pdf download

https://github.com/guoguoguilai/flutter-webview-blob-download

Display a bloc URL image in flutter)

final response = await get(
   Uri.parse(blob),
);
final documentDirectory = await getApplicationDocumentsDirectory();
final File file = File(join(documentDirectory.path, 'image.png'))
..writeAsBytesSync(response.bodyBytes);

Does anyone have a possible solution ?

Velliane
  • 65
  • 7

1 Answers1

0

you can use FileReader for getting bytes from blob here is example:

final blob = Blob(); // ==> this is your html.blob
      final reader = html.FileReader()..readAsDataUrl(blob); //=> read data 
      await reader.onLoadEnd
          .firstWhere((element) => element.isTrusted ?? false);
      webBytes = UriData.parse(reader.result.toString()).contentAsBytes();
lonly night
  • 61
  • 1
  • 1