download method
Future
download(
- String url,
- dynamic savePath, {
- Map<
String, dynamic> ? params, - Options? options,
- CancelToken? cancelToken,
- Map<
String, dynamic> ? queryParameters, - bool deleteOnError = true,
- String lengthHeader = Headers.contentLengthHeader,
- ProgressCallback? onReceiveProgress,
- OnSuccess? onSuccess,
- OnFailed? onFailed,
- OnCommon? onCommon,
- dynamic bind,
DOWNLOAD 请求
@param url
请求地址
@param savePath
文件下载路径
@param params
请求参数(可选)
@param options
请求额外设置,包括Header等(可选)
@param cancelToken
取消请求时使用的CancelToken(可选)
@param onReceiveProgress
请求响应进度回调方法(可选)
@param onSuccess
请求成功回调方法(可选)
@param onFailed
请求失败回调方法(可选)
@param onCommon
公共回调方法,成功和失败都会调用,在onSuccess和onFailed之前调用(可选)
deleteOnError
当下载失败时,是否删除已下载的文件,默认为true。
lengthHeader
原始文件的实际大小(未压缩)。
当文件被压缩时:
- 如果该值为 'content-length',则
onReceiveProgress
的 'total' 参数将为 -1 - 如果该值不是 'content-length',可能是自定义标头指示原始文件大小,则
onReceiveProgress
的 'total' 参数将是该标头值。 您还可以通过将 'accept-encoding' 标头值指定为 '*' 来禁用压缩,以确保onReceiveProgress
的 'total' 参数值不为 -1。 例如:
Implementation
Future<dynamic> download(
String url,
dynamic savePath, {
Map<String, dynamic>? params,
Options? options,
CancelToken? cancelToken,
Map<String, dynamic>? queryParameters,
bool deleteOnError = true,
String lengthHeader = Headers.contentLengthHeader,
ProgressCallback? onReceiveProgress,
OnSuccess? onSuccess,
OnFailed? onFailed,
OnCommon? onCommon,
dynamic bind,
}) async {
return _client!
.download(
_handleUrl(url, params),
savePath,
data: _handleParams(url, params),
options: _bindCancelToken(options, bind),
cancelToken: cancelToken,
queryParameters: queryParameters,
deleteOnError: deleteOnError,
lengthHeader: lengthHeader,
onReceiveProgress: onReceiveProgress,
)
._handleCallback(onSuccess, onFailed, onCommon);
}