Dart version of Simple file downloader
Features
- pure dart
- support resume from breakpoint
- support progress and speed callback
Getting started
Usage
//init
//open log , close default
FileDownloader.openLog = true;
//custom your dio . not necessary.
//FileDownloader.dio = Dio();
//default download save dir, must be set if not set filePath when download
FileDownloader.globalSaveDir = "/Users/hss/Downloads";
var url = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WeAreGoingOnBullrun.mp4";
FileDownloader(
url: url,
//filePath: "/Users/hss/Downloads/WeAreGoingOnBullrun-2.mp4",
onSuccess: (url, filePath) {
//print('下载成功: $url -> $filePath');
},
).start();
//cancel download
Future.delayed(Duration(seconds: 3)).then((value) => FileDownloader.cancel(url));
the fileDownloader support configs:
FileDownloader({
required this.url,
this.filePath,
this.fileName,
this.saveDir,
this.forceRedownload,
this.notAcceptRanges,
this.headers = const {},
this.fileSizeAlreadyKnown,
this.onStartReal,
this.onFailed,
this.progressCallbackIntervalMills = 300,
this.retryTimes = 1,
this.tags = const {},
required this.onSuccess,
this.onProgress,
this.onCancel,
});
some case
file already downloaded:
reqeust started then canceled when downloading:
resume downloading from breakpoint
And finally download success:
a response without content-length:
Additional information
Libraries
- simple_file_downloader_dart
- Support for doing something awesome.