downloader

Downloader模块管理网络文件下载任务,用于从服务器下载各种文件,并支持跨域访问操作。通过plus.downloader获取下载管理对象。Downloader下载使用HTTP的GET/POST方式请求下载文件,符合标准HTTP/HTTPS传输协议。

方法:

对象:

回调方法:

权限:

5+功能模块(permissions)

{
// ...
"permissions":{
	// ...
	"Downloader": {
		"description": "文件下载,管理文件下载任务"
	}
}
}
			

Download

Download对象管理一个下载任务

interface plus.downloader.Download {
	readonly attribute String id;
	readonly attribute String url;
	readonly attribute Number state;
	readonly attribute DownloadOptions options;
	readonly attribute String filename;
	readonly attribute Number downloadedSize;
	readonly attribute Number totalSize;
	function void abort();
	function void addEventListener(String event, function Callback listener, Boolean capture);
	function String getAllResponseHeaders();
	function String getResponseHeader(String headerName);
	function void pause();
	function void resume();
	function void setRequestHeader(String headerName, String headerValue);
	function void start();
}
				

属性:

方法:

DownloadEvent

下载任务事件类型

常量:

DownloadState

下载任务状态

常量:

DownloadOptions

下载任务参数

interface plus.downloader.DownloadOptions {
	readonly attribute String method;
	readonly attribute String data;
	readonly attribute String filename;
	readonly attribute Number priority;
	readonly attribute Number timeout;
	readonly attribute Number retry;
	readonly attribute Number retryInterval;
}
				

说明:

在创建下载任务时设置的参数,如设置下载任务使用的HTTP协议类型、优先级等。

属性:

DownloadCompletedCallback

下载任务完成时的回调

vaoid onCompleted(Download download, Number status) {
	// Download file complete code
}
				

说明:

下载任务完成时的回调函数,在下载任务完成时调用。 下载任务失败也将触发此回调。

参数:

返回值:

void : 无

DownloadStateChangedCallback

下载任务状态变化回调

void onStateChanged( Download download, status ) {
	// Download state changed code.
}
				

参数:

返回值:

void : 无

DownloadEnumerateCallback

枚举下载任务回调

void onEnumerated( Download[] downloads ) {
	// Enumerate success code
}
				

参数:

返回值:

void : 无