我有一个名为Upload的屏幕,用户可以通过输入描述和多个图像上传帖子,并在主页上检索Firestore的数据。
问题是,在上传屏幕中,当我按下将图像及其URL上传到Firebase存储时,存储多个图像没有问题,但在Firestore中存储URL有问题。
的数据
我试过了:
Widget postButton(){
return RaisedButton(
shape:RoundedRectangleBorder( borderRadius: BorderRadius.circular(15.0),),
color: Color.fromRGBO(0,21,43,1),
onPressed: () {
uploadToFirebase();
UploadPost();
},
textColor: Colors.white,
padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: Container(
alignment: Alignment.center,
width: _width/1.7,
child: Text(
"Upload Post",
style: TextStyle(
fontSize: 16.0,
),
),
),
);
}
void UploadPost() async{
UserManagement().addPost(Name,Des,UserImageUrl,ImageUrl,PhoneNumber, context);
}
void uploadToFirebase() async{
_paths.forEach((fileName, filePath) => {upload(fileName, filePath)});
}
void upload(fileName, filePath) async{
DateTime date = new DateTime.now();
var Date = DateFormat('EEE d MMM kk:mm:ss').format(date);
StorageReference storageRef = FirebaseStorage.instance.ref().child("User Posts").child('$PhoneNumber').child('$Date').child('$date');
final StorageUploadTask uploadTask = storageRef.putFile(File(filePath));
var downUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
var url = downUrl.toString();
print(url);
setState(() {
ImageUrl = url;
print("Done");
print(ImageUrl);
});
}
字符串
1条答案
按热度按时间mwngjboj1#
获取
url
后,您可以在firestore中存储:字符串
这将把
url
添加到文档中