[英]How to upload image files to FIRESTORE using crud method?
I'm currently uploading some data to firestore:我目前正在将一些数据上传到 firestore:
Map<String, dynamic> ads = {
'adTitle': widget.title,
'adPrice': widget.price,
'adCategory': widget.dropdownValue,
'adCondition': this.newCondtionVal,
'adDesc': widget.desc,
'user_id': uID,
///TODO upload the images.
};
crudObj
.addData(ads)
.then((value) => {
showInSnackBar("dataAdded"),
})
.catchError((e) {
print(e);
});
Images selected via Image_Picker, the question is how can I upload it to firebase using the method mentioned above.通过Image_Picker选择的图片,问题是如何使用上述方法上传到firebase。
PS: I'm a newbie to Flutter and Firebase stuff. PS:我是 Flutter 和 Firebase 的新手。
you can convert your image to base64 and give to the firebase which gives you the getDownloadURL
.您可以将图像转换为 base64 并提供给 firebase ,它为您提供getDownloadURL
。 That getDownloadURL
should be saved somewhere so you can access it and show it into your flutter app.该getDownloadURL
应该保存在某个地方,以便您可以访问它并将其显示到您的 flutter 应用程序中。
I have a code snippet which you can refer it我有一个代码片段,你可以参考它
Future uploadFile() async {
StorageReference storageReference = FirebaseStorage.instance
.ref()
.child('chats/${Path.basename(_image.path)}}');
StorageUploadTask uploadTask = storageReference.putFile(_image);
await uploadTask.onComplete;
print('File Uploaded');
storageReference.getDownloadURL().then((fileURL) {
setState(() {
_uploadedFileURL = fileURL;
});
});
}
This is about a firebase real-time database.这是关于一个firebase的实时数据库。 if you need for firebase database then please let me know.如果您需要 firebase 数据库,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.