Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Uint8List to File

I'm using Image Picker web which works well. I can display image in Image.memory(), but this image in format Uintlist8. For save in storage need format File, my issue is how to save an image in Firebase Storage.

Web image picker:

class _SecondPageState extends State<SecondPage> {
  final _formkey = GlobalKey<FormState>();
  Uint8List _image;

  getImage() async {
    Uint8List tempImg = await ImagePickerWeb.getImage(asUint8List: true);
    if (tempImg != null) {
      setState(() {
      _image = tempImg;
    });
  }
}
like image 235
Andrey Khan Avatar asked Oct 23 '25 14:10

Andrey Khan


1 Answers

Please Try ....

final _formkey = GlobalKey<FormState>();
  Uint8List _image;
 getImage() async {
 Uint8List tempImg = await ImagePickerWeb.getImage(asUint8List: true);
 if (tempImg != null) {
  setState(() {
  _image = tempImg;
  final tempDir = await getTemporaryDirectory();
  final file = await new File('${tempDir.path}/image.jpg').create();
  file.writeAsBytesSync(_image);
  });
 }
}
like image 119
Madhusudhan Sahni Avatar answered Oct 26 '25 04:10

Madhusudhan Sahni