'Set and get Image in objectbox
I want to set and get image from local storage, but I have no idea how to do this.
Solution 1:[1]
I have done with the help of http and base64String
Future<String> getNetworkImage()async{
final data = await _firestore.collection("[email protected]").doc("GymDetails").get();
final imageurl = data.get("url");
final uri = Uri.parse(imageurl);
final response = await http.get(uri);
final unit8listimage = response.bodyBytes;
final base64image = base64Encode(unit8listimage);
final object = SetImage(imageurl: base64image);
if(!_objectBox.setimage.isEmpty()){
_objectBox.setimage.remove;
}
_objectBox.setimage.put(object);
final getimage = _objectBox.setimage.get(object.id);
return getimage!.imageurl;
}
Solution 2:[2]
I don't know what your want image format is, but most likely you can use base64.
Probably this page will be helpful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Cristik |
Solution 2 |