Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i upload and download pdf in firebase flutter

Is it possible to upload pdf in firebase collection in Flutter.
How can download pdf from firebase

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Firebase Realtime Database or Firebase Cloud Firestore can not host any file. But Firebase has a product called Cloud Storage that can host the files and actually keep reference to it in your Cloud Firestore.

What you need to do is to first upload the file and then get the URL of it and keep it in your Cloud Firestore:

Future<String> uploadFile(String filePath) async {
  File file = File(filePath);

  try {
    await firebase_storage.FirebaseStorage.instance
        .ref('uploads/bills.pdf')
        .putFile(file);
  String downloadURL = await firebase_storage.FirebaseStorage.instance
      .ref('uploads/bills.pdf')
      .getDownloadURL();
       
      return downloadUrl;
  } on firebase_core.FirebaseException catch (e) {
    print(e);
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading