This is my code
var byte = File(item.path).readAsBytesSync();
String img64 = base64Encode(byte);
And I have a result like:
(/9j/4TY3RXhpZgAASUkqAAgAAAALADIBAgAUAAAAkgAAABABAgAaAAAApgAAAAABBAABAAAAwAMAABMCAwABAAAAAQAAACgBAwABAAAAAgAAAAEBBAABAAAAwAMAABsBBQABAAAAwAAAABIBAwABAAAAAQAAAGmHBAABAAAA1wAAABoBBQABAAAAyAAAAA8BAgAHAAAA0AAAALUBAAAyMDIzOjExOjIxIDEzOjMyOjQ5AEFuZHJvaWQgU0RLIGJ1aWx0IGZvciB4ODYASAAAAAEAAABIAAAAAQAAAEdvb2dsZQAOAAGgAwABAAAA)
But I want to have a result like this:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3gAAALyCAYAAACIMnZEAAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzsvXd8XMW9sP/MOWertGqWrGbLBSPbuIALtummGXAw5QIhJr/7JpDCJYSEAJeUl18wgRtyEyAJgSSQkJBGCwkdnFBMCS64gXvvsrosabX9nDPvH2d3t
2
Answers
you just need to concatenate
data:image/png;base64,
with base64 Stringlike this:
The Dartk SDK includes a
UriData
class that can do it for you.From there, you can use
uriData.toString()
to get aString
representation oruriData.uri
to get aUri
object.