Here I have note down some important information, that you might find useful when you work with ImagePicker() plugin and Firebase Storage for file uploading.
What does imagePicker() return?
It returns a XFile object
How to get the image path from XFile object?
You can get by xFileObjet.path
Why do you need File() constructor?
We need it to create a local copy of the XFile or Image object.
What else File() does?
It takes a file path and creates a copy of the file in FileSystem of OS.
What does File() take as argument ?
It takes file path as an argument.
How to create a space in Firebase Storage for uploading images?
You may use the below syntax to do it.
FirebaseStorage.instance.ref(“chat”).child(name)
It will create a folder or tag like using name “chat” and “name” represents the actual file you uploaded. It will return an object. Save that object.
What function to use to get the URL of FirebaseStorage uploaded image?
getDownloadURL()
Why should you get the url returned from FirebaseStorage?
It’s a general practice, more importantly you should be using it later in the chat.
We save it in our history in the database.
Which Firebase function helps you to get upload a file to Firebase Storage?
it’s putFile() function.
How do you get putFile() function?
You get it from FirebaseStorage.intance.(“foldername”).child(name). This syntax returns a reference object. You can use that object to access putFile().
What else does putFile() provide?
It provides snapshotEvents() for listening to File upload. We may listen to file upload using putFile(filePath).snapshotEvents.listen((event)){}
Good post, thanks for share brother!