//初始化
var uploader = WebUploader.Uploader({...});
var getFileBlob = function (url, cb) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "blob";
xhr.addEventListener('load', function() {
cb(xhr.response);
});
xhr.send();
};
var blobToFile = function (blob, name) {
blob.lastModifiedDate = new Date();
blob.name = name;
return blob;
};
var getFileObject = function(filePathOrUrl, cb) {
getFileBlob(filePathOrUrl, function (blob) {
cb(blobToFile(blob, 'test.jpg'));
});
};
//需要编辑的图片列表
var picList = ['图片url','图片url','图片url','图片url' ]
$.each(picList, function(index,item){
getFileObject(item, function (fileObject) {
var wuFile = new WebUploader.Lib.File(WebUploader.guid('rt_'),fileObject);
var file = new WebUploader.File(wuFile);
uploader.addFiles(file)
})
});
reloadFileList();
function reloadFileList(){//执行附件列表
jQuery.ajax({
type : 'post',
url : webuploaderoptions.reloadUrl,
data: webuploaderoptions.reloadParam,
async: false,
dataType: 'json',
success : function(data) {
if(data.code == 200){
$(data.body).each(function(index) {
var _this = this;
var obj ={};
obj.name = _this.fileOldName;
obj.size = _this.fileSize;
obj.lastModifiedDate = _this.fileScsj;
obj.id = index;
obj.ext = _this.fileExtName;
obj.uuid = _this.uuid;
if(obj.size == undefined ||obj.size == 0){
obj.size = 1;//size不能为0
}
// new File( this._ruid, file )
// // var file = new WebUploader.File(obj);
// let file = new File( this._ruid, obj )
// console.log(file);
const filePathOrUrl='/fileup/downFile.html?uuid='+ obj.uuid;
getFileObject(filePathOrUrl, function (fileObject) {
var wuFile = new WebUploader.Lib.File(WebUploader.guid('rt_'),fileObject);
wuFile.uuid=obj.uuid;
var file = new WebUploader.File(wuFile);
uploader.addFile(file);
uploader.initFiles(file, {"fileId":_this.fileId,"code":200,"msg":"上传成功",judgDel:webuploaderoptions.reloadParam ? webuploaderoptions.reloadParam.canDelete : true,"uuid":_this.uuid});
})
});
}else{
alert(data.msg);
}
},
error : function(jqXHR, textStatus, errorThrown) {
alert("【"+textStatus+"】"+jqXHR.responseText);
}
});
}
08-18
107
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交