Flutter&Firebase:上传图片前先压缩
问题内容:
我想将用户在应用程序中选择的照片发送到Firebase Storage。我有一个简单的类,其属性_imageFile
设置如下:
File _imageFile;
_getImage() async {
var fileName = await ImagePicker.pickImage();
setState(() {
_imageFile = fileName;
});
}
之后,我使用以下代码发送照片:
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中是否有任何方法可以在上传之前对照片进行压缩和调整大小?我对质量下降没事。
问题答案: