我想将用户在我的应用中选择的照片发送到Firebase存储.我有一个简单的类属性_imageFile,其设置如下:
File _imageFile;
_getImage() async {
var fileName = await ImagePicker.pickImage();
setState(() {
_imageFile = fileName;
});
}
Run Code Online (Sandbox Code Playgroud)
之后,我发送照片与此代码:
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);
Run Code Online (Sandbox Code Playgroud)
问题是照片通常非常大.在上传之前,Flutter/Dart中是否有任何压缩和调整照片大小的方法?我很好,质量下降.