# download
从网络上下载文档存在本地。来源自 Cordova API (opens new window)。
# 输入
继承标准对象输入,扩展属性描述
| 名称 | 数据类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| uri | string | 是 | 文件的网络地址 | |
| filePath | string | 是 | 保存的路径 |
# 输出
继承标准对象输出,无扩展属性
# 示例代码
//获取应用相关的目录,android和ios的目录结构不同
//android下可以存储在 /sdcard/download下面
//ios只能存储在应用里面
app.getAppDirectoryEntry(function(res){
//区分平台,并将相应的目录保存到全局,方便下面下载的时候使用
if(window.devicePlatform=="android"){
window.savePath=res.sdcard;
}else if(window.devicePlatform=="iOS"){
window.savePath=res.documents;
}
//下载文件
var fileTransfer=new FileTransfer();
var uri=encodeURI("http://developer.bingosoft.net/bingotouch.docx");
var filePath=window.savePath+"/bingotouch.docx";
fileTransfer.download(
uri,
filePath,
function(entry){
app.hint("下载完成:" + entry.fullPath);
},
function(error){
app.hint("下载失败");
}
);
});