gpt4 book ai didi

mysql - 无法将来自 JSON 的 Blob 转换为文件

转载 作者:行者123 更新时间:2023-12-03 22:30:24 25 4
gpt4 key购买 nike

我在 mySQL 上保存了一个 base64 编码的图像。当我使用 API 获取图像时,它返回一个 Blob:
Blob on Json
但是当我尝试获取 Blob 时,我收到错误:

'_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'


该错误发生在 base64.decode(pictureBlob) 行上,因此 Blob 是一个列表。但是我怎么能正确地得到 Blob?
我用来获取 Blob 的代码:
  Future<Profile> getProfile(ModelUser user) async {
_headers['Authorization'] = "Bearer ${user.token}";

final response = await get(
Uri.http(_options.baseUrl, '/persons/${user.id}'),
headers: _headers);

if (response.statusCode == 200) {
print("ui");
Map<String, dynamic> profileMap = jsonDecode(response.body);
var pictureBlob = profileMap['picture'];

print(pictureBlob);
print(base64.decode(pictureBlob));

return Profile.fromJson(profileMap);
}

最佳答案

看看你的json。通过 var pictureBlob = profileMap['picture']; 这一行你会得到一张 map

{
"type" : "Buffer",
"data" : [47, 57, ......]
}
所以要获取您需要使用的 blob 文件
//getting the blob from json
var pictureBlob = profileMap['picture']['data'];
//convert it to Uint8List
var image = base64.decode(pictureBlob);
然后使用图像作为 Image.memory(image);

关于mysql - 无法将来自 JSON 的 Blob 转换为文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67629301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com