Convert Uint8List to File

Viewed 10281

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;
    });
  }
}
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);
  });
 }
}
Related