var pkAttach = item.affixId;
var fileName = item.fileName;
var fileTempName = pkAttach + ".tmp";
var filePath = pkAttach;
var fullFilePath = "_downloads/"+ filePath;
var downFilePathName = filePath + fileName;
var downFileTempPathName = filePath + fileTempName;
var percent = "";
var task =plus.createDownloadTask(url, downFileTempPathName, function(task, status) {
if(url.indexOf("assetsManageAction_downFile.do") != -1||url.indexOf("knowledge_downloadKnowledgeAttr.do") != -1||url.indexOf("notice_downloadNoticeAttr.do") != -1||url.indexOf("myWork_downloadWorkAttr.do") != -1) {
if(task.__responseHeaders__.totalSize==0){
mui.toast("文件为空");
item.state='no';
context.$set(context.trueItems, index, item)
return;
};
};
var realFileTempName = task.filename.replace(fullFilePath, ""); //有时候下载失败也会生成临时文件,而系统默认会追加数字命名,所以这里以实际返回的下载成功文件名为依据
plus.io.resolveLocalFileSystemURL(fullFilePath, function(pathEntry) { //打开父目录
pathEntry.getFile(realFileTempName, { //找到临时文件
create: false
}, function(temFileEntry) {
//把临时文件名改成实际文件名
var tempFileName = fileName;
//当文件名过长时,截取一个短的名称,防止过长时无法存在我们的手机中
var tmp = fileName.split(".");
//先判断当前文件是否有后缀名
if(tmp.length > 0) {
if(tmp[0].length > 40) {
tempFileName = tmp[0].substr(0, 40) + "." + tmp[1];
}
} else {
if(fileName.length > 0) {
tempFileName = fileName.substr(0, 40);
}
}
context.tempFileName = tempFileName;
context.moveTempToReal(pathEntry, temFileEntry, pkAttach, fileName, tempFileName, 0);
}, function(e) {
item.state = 'no';
context.$set(context.trueItems, index, item)
mui.toast("[" + fileName + "]下载失败,解析临时文件失败:" + e.message);
});
}, function(e) {
item.state = 'no';
context.$set(context.trueItems, index, item)
mui.toast("[" + fileName + "]下载失败,解析临时目录失败:" + e.message);
});
}, function(msg) {
item.state = 'no';
context.$set(context.trueItems, index, item)
mui.toast("[" + fileName + "]下载失败:" + msg);
}, function(task, status) {
if(url.indexOf("assetsManageAction_downFile.do") != -1||url.indexOf("knowledge_downloadKnowledgeAttr.do") != -1||url.indexOf("notice_downloadNoticeAttr.do") != -1||url.indexOf("myWork_downloadWorkAttr.do") != -1) {
percent = Math.floor((task.downloadedSize / task.__responseHeaders__.totalSize) * 100);
} else {
percent = Math.floor((task.downloadedSize / task.totalSize) * 100);
}
});
this.attachmentObj.startDownloadTask(task);
//把任务对象与当前下载关联并缓存
item.taskId = task.id;
this.taskJson[task.id] = task;
pauseDownloadTask = function (dtask){
console.log("pause--taskId:" + item.taskId + " taskTemp--downloadedSize:" + JSON.stringify(taskTemp.downloadedSize));
dtask.pause();
}
resumeDownloadTask = function (dtask){
console.log("resume--taskId:" + item.taskId + " taskTemp--downloadedSize:" + JSON.stringify(taskTemp.downloadedSize));
dtask.resume();
}
问题描述:
点击附件下载暂停,然后点击继续下载,下载任务返回的download文件已下载的大小就会出现问题。
打印的日志:
pause--taskId:dt61537263165959 taskTemp--downloadedSize:487376
resume--taskId:dt61537263165959 taskTemp--downloadedSize:945522
pause--taskId:dt61537263165959 taskTemp--downloadedSize:774144
这到底是什么原因呢?
0 个回复