我仍然在为这个恼人的错误而挣扎。我有base64字符串,我想要转换成图像。下面是最简单的代码,它正在做我想做的事情(至少,我在SO上看到了不同的答案和代码样本)。我发现了一个错误:
Invalid character (at character 6)我的代码是:
final String encodedStr = 'https://securelink.com/cameratypes/picture/13/true';
Uint8List bytes = base64.decode(encodedStr);我想展示一下图像:
Image.memory(bytes)发布于 2022-02-15 13:15:15
最后,我找到了解决方案,我不知道它是否重要,对任何像我这样挣扎的人都会有用,但我会帮助你的。因此,这将是简单而快速的,因为我已经将我的图像转换为ne契据formart (我的图像是base64格式),当我再次尝试将它转换成字符串时,我犯了一个愚蠢的错误,因为它已经是一个字符串,我需要Uint8List格式。附带注意:如果您的api开发人员说它应该使用cookie或任何类型的auth,那么它应该是这样的。
代码:
Future<String> _createFileFromString() async {
final response = await http.get(
Uri.parse(
'your link here',
),
headers: {
'cookie':
'your cookie here'
});
final Uint8List bytes = response.bodyBytes;
String dir = (await getApplicationDocumentsDirectory()).path;
String fullPath = '$dir/abc.png';
print("local file full path ${fullPath}");
File file = File(fullPath);
await file.writeAsBytes(List.from(bytes));
print(file.path);
final result = await ImageGallerySaver.saveImage(bytes);
print(result);
return file.path;
}此代码将您的图像直接保存到应用程序库,并且不在屏幕上显示任何内容。
https://stackoverflow.com/questions/71109437
复制相似问题