TSR
TSR

Reputation: 20416

How to decode or convert base64 string url to UintList in Dart?

I got this base64Result from canvas.toDataURL() but I having difficulties parsing in Dart to 'UintList'

  import 'dart:convert';

  final String base64Result = result.toString();
  print("$logTrace calling web function done ${base64Result.length}");
  final bytes = base64Url.decode(base64Result);


character (at character 5)
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARwAAAIrCAYAAAA9YyZoAAAgAElEQ...
    ^

Upvotes: 0

Views: 457

Answers (1)

jamesdlin
jamesdlin

Reputation: 89985

'data:image/png;base64,' is part of the data URL, not part of a base-64 string. You need to extract the base-64 data from the URL first.

Luckily, the UriData class can do this all for you:

final bytes = UriData.parse(base64Result).contentAsBytes();

Upvotes: 1

Related Questions