将Uint8List转换为文件



我使用的是Image Picker web,它运行良好。我可以用Image.memory()显示图像,但此图像的格式为Uintlist8。对于存储中的保存需要格式File,我的问题是如何在Firebase storage中保存映像。

Web图像选择器:

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

请尝试。。。。

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

最新更新