我正在将保存在Firebase数据库中的图像转换为Base64,并希望对其进行解码和编码.我研究了类似的问题,但我仍然遇到错误.这是我到目前为止的情况?
var image1 = String;
var pic = event.snapshot.value['image'];
var photo = BASE64.decode(pic);
image1 = photo;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误...
A value of type "List<int>" cannot be assigned to a variable of type "Type"
如果你能提供一个反向过程来将图像编码到Base64中,那么它们可以保存回Firebase,这将是值得赞赏的.
***更新
这是我的更新代码,仍然会抛出错误.
image1 = event.snapshot.value['image'];
var image = BASE64.decode(image1.toString());
new Image.memory(image),
Run Code Online (Sandbox Code Playgroud)
错误是......
FormatException: Invalid Length must be a multiple of 4
我正在努力下载图片然后在页面上显示它.打印base64编码的字符串看起来不对; 它与例如http://www.freeformatter.com/base64-encoder.html结果不同.
这是我的代码:
HttpRequest.request(_url).then((HttpRequest response) {
String contentType = response.getResponseHeader('Content-Type');
if (_supportedContentType(contentType)) {
List bytes = new Utf8Encoder().convert(response.responseText);
String header = 'data:$contentType;base64,';
String base64 = CryptoUtils.bytesToBase64(bytes);
String image = "${header}${base64}";
me.avatar = image;
print(image);
}
}
Run Code Online (Sandbox Code Playgroud)