I'm currently uploading some data to 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.
PS: I'm a newbie to Flutter and Firebase stuff.
you can convert your image to base64 and give to the firebase which gives you the getDownloadURL
. That getDownloadURL
should be saved somewhere so you can access it and show it into your flutter app.
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. if you need for firebase database then please let me know.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.