Is it possible to upload pdf in firebase collection in Flutter. How can download pdf from firebase
CodePudding user response:
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);
}
}