Last active
August 25, 2023 19:29
-
-
Save mateisilviu/5ef432baf964942a9e98d01fd51a8257 to your computer and use it in GitHub Desktop.
Flutter Web download pdf as files from Firebase storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:html' as html; | |
import 'dart:typed_data'; | |
import 'package:cross_file/cross_file.dart'; | |
import 'package:firebase_storage/firebase_storage.dart'; | |
downloadFileWeb(String url,String fileName) async { | |
final httpsReference = FirebaseStorage.instance.refFromURL(url); | |
try { | |
const oneMegabyte = 1024 * 1024; | |
final Uint8List? data = await httpsReference.getData(oneMegabyte); | |
// Data for "images/island.jpg" is returned, use this as needed. | |
XFile.fromData(data!, | |
mimeType: "application/octet-stream", name: fileName + ".pdf") | |
.saveTo("C:/"); // here Path is ignored | |
} on FirebaseException catch (e) { | |
// Handle any errors. | |
} | |
// for other platforms see this solution : https://firebase.google.com/docs/storage/flutter/download-files#download_to_a_local_file | |
} | |
previewPDFFile(url) { | |
html.window.open(url,"_blank"); //opens pdf in new tab | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment