尝试使用flutter将两张图片上传到Firebase中。该代码仅适用于一张图片,而针对两张图片进行编码!没有编译器错误!
File _image,_imageside;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
var image2 = await ImagePicker.pickImage(source:ImageSource.gallery);
setState(() {
_image = image;
_imageside = image2;
});
}
final DatabaseReference database = FirebaseDatabase.instance.reference().child("test");
sendData(){
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(name).child('front');
final StorageUploadTask task = firebaseStorageRef.putFile(_image);
FirebaseStorage.instance.ref().child(name).child('side');
final StorageUploadTask task1 =
firebaseStorageRef.putFile(_imageside);
};
_image == null ? new Text('No image selected.') : Text('Image selected'),
_imageside ==null? new Text('No image selected.'):Text("Image selected"),
RaisedButton(
onPressed: getImage,
child: new Icon(Icons.add_a_photo),
),
RaisedButton(
color: Colors.blueAccent,
onPressed: () =>sendData(),
child:
Text("Upload Data"),
)
答案 0 :(得分:0)
两个图像都使用相同的StorageReference
-因此,第二个图像将覆盖第一个图像。
将FirebaseStorage.instance.ref().child(name).child('side');
分配给新变量,然后用新的task1
上传StorageReference
。