有没有办法用 flutter 从 firebase 存储下载文件夹?
Is there a way to download folder from firebase storage with flutter?
我想从 firebase 存储下载 .epub 文件。我可以下载图像文件,因为我知道 imageUrl 但不知道 .epub 文件 url。我应该怎么做?我将 fileName、imageUrl 存储在 Firestore 中,但我不知道 epub 文件的 url 。所以我不能存储它。
downloadFile(fileName,imageUrl) async{
Dio dio=Dio();
final storageRef=FirebaseStorage.instance.ref();
final imageUrls =await storageRef.child("Featured").child('a clock orange/Anthony-Burgess-A-Clockwork-Orange-W.-W.-Norton-_-Company-_1986_.epub').getDownloadURL();
String savePath= await getPath(fileName);
dio.download(imageUrls, savePath,
onReceiveProgress: (rcv,total){
setState((){
progress=((rcv/total) *100).toStringAsFixed(0);
});
if (progress == '100') {
setState(() {
isDownloaded = true;
});
}
}).then((_){
if (progress=="100"){
setState(() {
isDownloaded=true;
});
}
});}
我试过了。但是没用。
.
使用 Firebase 的 writeToFile
而不是 dio 的 download
。
final fileRef = storageRef.child("<path here>");
final appDocDir = await getApplicationDocumentsDirectory();
final filePath = "${appDocDir.absolute}/<path here>";
final file = File(filePath);
final downloadTask = fileRef.writeToFile(file);
downloadTask.snapshotEvents.listen((taskSnapshot) {
...
}
我想从 firebase 存储下载 .epub 文件。我可以下载图像文件,因为我知道 imageUrl 但不知道 .epub 文件 url。我应该怎么做?我将 fileName、imageUrl 存储在 Firestore 中,但我不知道 epub 文件的 url 。所以我不能存储它。
downloadFile(fileName,imageUrl) async{
Dio dio=Dio();
final storageRef=FirebaseStorage.instance.ref();
final imageUrls =await storageRef.child("Featured").child('a clock orange/Anthony-Burgess-A-Clockwork-Orange-W.-W.-Norton-_-Company-_1986_.epub').getDownloadURL();
String savePath= await getPath(fileName);
dio.download(imageUrls, savePath,
onReceiveProgress: (rcv,total){
setState((){
progress=((rcv/total) *100).toStringAsFixed(0);
});
if (progress == '100') {
setState(() {
isDownloaded = true;
});
}
}).then((_){
if (progress=="100"){
setState(() {
isDownloaded=true;
});
}
});}
我试过了。但是没用。
.
使用 Firebase 的 writeToFile
而不是 dio 的 download
。
final fileRef = storageRef.child("<path here>");
final appDocDir = await getApplicationDocumentsDirectory();
final filePath = "${appDocDir.absolute}/<path here>";
final file = File(filePath);
final downloadTask = fileRef.writeToFile(file);
downloadTask.snapshotEvents.listen((taskSnapshot) {
...
}