我想从防火墙存储中下载.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;
});
}
});}我试过这个。但没起作用。
。

发布于 2022-05-19 15:10:05
使用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) {
...
}详情请参见下载到本地文件。
https://stackoverflow.com/questions/72302984
复制相似问题