(function(window) {
/**
下載文件
@method app.download
@static
@param option {object}
@param option.url {string} 下載的地址
*/
app.download = function(option) {
if (option && !option.attachmentUrl) {
return;
}
var docuementName = option.attachmentName;
var filePath = window.savePath + "/" + docuementName;
console.log('下載處的filepath',filePath)
var url = option.attachmentUrl;
var fileTransfer = new FileTransfer();
fileTransfer.download(
url,
filePath,
function(entry) {
//將文件路徑保存起來,方便后面調用
window.fileUri = entry.fullPath.replace("file:///", "file://");
var URL = window.fileUri;
app.openFile(URL, "", function(res) {
app.hint("打開成功!");
});
},
function(error) {
console.log('打開失敗')
app.hint("下載失敗!");
}
);
};
})(window);