我想将用户在我的应用程序中 Select 的照片发送到Firebase存储.我有一个属性为_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);
问题是这些照片通常非常大.在上传前,有没有什么方法可以在flift/Dart中压缩照片并调整其大小?我不介意质量下降.