I am trying to download file using Dio and pathProvider but it is getting failed i tried This Soln however the print progress is showing that it is dowloaded 100% and No error is thrown but i could not find the downloaded file i am using Android 13 Api 33
void onDownloadClick(String url) async {
String fileName = url.split("/").last;
var tempDir = await getTemporaryDirectory();
String fullPath =tempDir.path.toString() +"/" + fileName;
debugPrint('full path ${fullPath}');
var dio = Dio();
download2(dio, url, fullPath);
}
Future download2(Dio dio, String url, String savePath) async {
try {
Response response = await dio.get(
url,
onReceiveProgress: showDownloadProgress,
//Received data with List<int>
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
validateStatus: (status) {
return status! < 500;
},),
);
debugPrint(response.headers.toString());
File file = File(savePath);
var raf = file.openSync(mode: FileMode.write);
// response.data is List<int> type
raf.writeFromSync(response.data);
await raf.close();
} catch (e) {
debugPrint("Got Error ${e.toString()}");
}
}
void showDownloadProgress(received, total) {
if (total != -1) {
debugPrint((received / total * 100).toStringAsFixed(0) + "%");
}
}
Thanks