how to store Uint8List in mysql

454 Views Asked by At

I'm trying to store images in the database by converting them to Uint8List and then show images in flutter , I tried to store the Uint8List as TEXT and as VARCHAR and I have an error Expected value of type Uint8List and got 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

1

There are 1 best solutions below

1
On

I fixed it by using base64 encoding and decoding then storing the encoded image as Text in mysql and when i want to display my Image i used image.memory

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