How to set Bytes data in firebase using flutter?
Cloud Firestore raw bytes is represented by Blob
in Dart, so use:
.setData({'thumbnailPhoto', Blob(await file.readAsBytes())});
When you read this back from Cloud Firestore you'll get back a Blob
. Access its bytes with blob.bytes
. For example, to write to a file use:
await file.writeAsBytes(theBlob.bytes); // overwrite or create the file
In this case, you can convert the image to base64 string.
open image as:
var imageFile = File(imagePath);
convert to base64:
String base64Image = base64Encode(imageFile.readAsBytesSync());