颤振Firebase:上传图片前先压缩 [英] Flutter & Firebase: Compression before upload image

查看:74
本文介绍了颤振Firebase:上传图片前先压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将用户在我的应用中选择的照片发送到Firebase Storage。我有一个具有属性 _imageFile 的简单类,其设置如下:

I want to send photo selected by user in my app to Firebase Storage. I have a simple class with property _imageFile which is set like this:

File _imageFile;

_getImage() async {
    var fileName = await ImagePicker.pickImage();
    setState(() {
        _imageFile = fileName;
    });
}

之后,我发送带有以下代码的照片:

after that I send photo like with this code:

final String rand1 = "${new Random().nextInt(10000)}";
final String rand2 = "${new Random().nextInt(10000)}";
final String rand3 = "${new Random().nextInt(10000)}";
final StorageReference ref = FirebaseStorage.instance.ref().child('${rand1}_${rand2}_${rand3}.jpg');
final StorageUploadTask uploadTask = ref.put(_imageFile);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
print(downloadUrl);

问题是照片通常很大。 Flutter / Dart中是否有任何方法可以在上传之前对照片进行压缩和调整大小?我对质量下降没事。

The problem is that the photos are often very large. Is there any method in Flutter/Dart to compress and resize photo before upload? I am ok with loss of quality.

推荐答案

image_picker 插件目前非常简单。添加用于指定所拾取图像的所需大小/质量的选项将很简单。如果您这样做,请向我们发送请求请求!

The image_picker plugin is currently very simple. It would be straightforward to add an option for specifying the desired size/quality of the picked image. If you do this, please send us a pull request!

这篇关于颤振Firebase:上传图片前先压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆