flutter 如何在mysql中存储Uint8List [副本]

ddrv8njm  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(179)

此问题在此处已有答案

What data type to use in MySQL to store images?(3个答案)
14小时前就关门了。
我尝试通过将图像转换为Uint8List来将其存储在数据库中,然后在flutter中显示图像,我尝试将Uint8List存储为TEXT和VARCHAR,但出现错误预期值为Uint8List类型,但得到的是String

addimage(String x , Uint8List img)async{
    print (x);
    var url = 'http://ip/imageStore.php';
    var response = await http.post(Uri.parse(url), body :{
      'word': x,
      'imageByte': img,
    });


snapshot.data![index]['imageByte'] as Uint8List
vxbzzdmp

vxbzzdmp1#

我通过使用base64编码和解码修复了它,然后将编码后的图像作为文本存储在mysql中,当我想显示我的图像时,我使用了image.memory

image = base64Encode(Uint8List_image); // convert image to base64 (String);
       image.memory(base64Decode(image)); // convert encoded image to Uint8List and display it ;

相关问题