小编Cin*_*nik的帖子

如何在Dart中正确下载图片并转换为base64?

我正在努力下载图片然后在页面上显示它.打印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)

dart

4
推荐指数
1
解决办法
1629
查看次数

标签 统计

dart ×1