uploadFile method

Future<String> uploadFile({
  1. required String filePath,
  2. required String storagePath,
})

Uploads a file to Firebase Storage.

filePath: The local path of the file to upload. Example: /local/path/to/file.jpg

storagePath: The path in Firebase Storage where the file should be uploaded. Example: uploads/images/file.jpg

Returns a Future that resolves to the download URL of the uploaded file.

Implementation

Future<String> uploadFile(
    {required String filePath, required String storagePath}) async {
  File file = File(filePath);
  Reference storageReference = FirebaseStorage.instance.ref(storagePath);
  TaskSnapshot uploadTask = await storageReference.putFile(file);
  return await uploadTask.ref.getDownloadURL();
}