How to upload and download pdf files in flutter app using firebase storage
Your question has multiple parts:
For pdf viewing:
search in pub.dev for pdf and you'll find multiple packages.
For uploading using Firebase:
You can use the file_picker
package to allow the user to pick files. Then use firebase storage to upload that file.
StorageReference reference = FirebaseStorage.instance.ref().child(path);
StorageUploadTask uploadTask = reference.putFile(pickedFile);
StorageTaskSnapshot ref = await uploadTask.onComplete;
// to get the download URL and save it somewhere
String url = await reference.getDownloadURL();
Store the downloadUrl to use it later or you can get the downloadURL again using the same approach (i.e. reference.getDownloadURL()
)
For downloading:
You can either use the downloadURL directly to get the file and pass it to the pdf viewer, or use FirebaseStroage method reference.getData(maxSize)
but note you've to specify the maxSize. Then pass the data to the pdf viewer of your choice. Maybe you can find a viewer that will show data directly from URL and that'll make it easier.
Jatin Pandey
Updated on December 25, 2022Comments
-
Jatin Pandey over 1 year
I am making a flutter app in which I need to upload pdf files to firebase storage and then downloading and opening those pdf files from firebase storage to the android device. I dont know how to do this and there is no documentation on the flutter website for this also. Any help would be appreciated.