stsAccessKeyId = ""
stsAccessKeySecret = ""
stsToken = ""
var checkpoint_temp;
var requestUrl;
var returnUrl;
var str;
var buckName='newxgccpm'
function multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,size, cpt) {
console.log("-----------------------start");
// let BosClient = baidubce.sdk.BosClient
// // let config = {
// // endpoint: 'http://su.bcebos.com',
// // credentials: {
// // ak: '9915286aab2949949b489e8ab3f70a09', //您的AK
// // sk: '069036bdb93c4bc59c4995ccc543243e' //您的SK
// // }
// // }
// // let client = new BosClient(config);
multitest(storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,size, cpt);
};
function multitest (storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
// var buffer = new Buffer('123')
var formdata = new FormData();
formdata.append("storeAs",storeAs);
formdata.append("file",file);
var names = storeAs.split("/");
var name = names[names.length-1];
$.ajax({
type:'post',
url:realPath+"/bos/upload",
data:formdata,
contentType: false,
processData: false,
// progress: function* (percent, cpt) {
// console.log(cpt);
// console.log('Progress: ' + percent);
// var p = Math.floor(percent*100);
// $("#jindutiao"+divId).attr("style","width: "+p+"%");
// $("#jindutiao"+divId).attr("aria-valuenow",p+"%");
// $("#baifenbi"+divId).html(p+"%");
// $("#fileName"+divId).html(name);
// }
success:function (data1) {
if(data1.code==='1'){
returnUrl = realPath+"/sys/workattachment/saveAttachment";
var p = Math.floor(1*100);
$("#jindutiao"+divId).attr("style","width: "+p+"%");
$("#jindutiao"+divId).attr("aria-valuenow",p+"%");
$("#baifenbi"+divId).html(p+"%");
$("#fileName"+divId).html(name);
$.ajax({
type:'post',
url:returnUrl,
data:{
"attachmentName":file['name'],
"attachmentId":attachmentId,
"attachmentFlag":attachmentFlag,
"url":data1.url,
"divIdType":divId
},
success:function(data){
// console.log('ajax requst : ' + data.status);
console.log('url : ' + data.url);
if(data.status=="Success"){
parent.layer.msg("上传成功!",{icon:1});
var lenght =$(".trIdAdds").length;
if (size != 0){
lenght += size;
}
var addFile = "addFile"+divId;
var str = '
'+
'' ;
if (isContains("jpg,png,gif,bmp,jpeg",data.type)){
str = str +' ';
}else if(isContains("pdf",data.type)){
str = str + ''+data.attachmentName+'';
}else {
str = str + ''+data.attachmentName+'';
}
str = str +' | '+
''+data.createByName+' | '+
''+data.createDate+
''+
''+
''+
''+
''+
''+
''+
' | '+
''+
'' +
' | '+
'
';
console.log("file:"+divId);
console.log("str="+str);
$("#file"+divId).append(str);
// $("img").not(".upload_ico").each(function () {
// var num = 1 ;
// $(this).live("click",function () {
// var flag = num%2;
// if(flag == 1){
// $(this).css("width","90%");
// $(this).css("height","90%");
// num++;
// }else if(flag ==0){
// $(this).css("width","50px");
// $(this).css("height","50px");
// num++;
// }
// })
// });
}else {
parent.layer.msg("上传失败!",{icon:2});
}
}
})
}else {
parent.layer.msg("上传失败!",{icon:2});
}
}
})
// var names = storeAs.split("/");
// var name = names[names.length-1];
// client.putObjectFromString(buckName,file, '/1/1'
// ).then(function (result) {
// console.log("uploadPath:"+uploadPath);
// console.log("rusult:"+result);
// console.log("end-------result:");
// returnUrl = realPath+"/a/sys/workattachment/saveAttachment";
// $.ajax({
// type:'post',
// url:returnUrl,
// data:{
// "attachmentName":file['name'],
// "attachmentId":attachmentId,
// "attachmentFlag":attachmentFlag,
// "url":uploadPath
// },
// success:function(data){
// console.log('ajax requst : ' + data.status);
// if(data.status=="Success"){
// parent.layer.msg("上传成功!",{icon:1});
// var lenght =$(".trIdAdds").length;
// if (size != 0){
// lenght += size;
// }
// var addFile = "addFile"+divId;
// var str = ''+
// '' ;
// if (isContains("jpg,png,gif,bmp,jpeg",data.type)){
// str = str +' ';
// }else if(isContains("pdf",data.type)){
// str = str + ''+data.attachmentName+'';
// }else {
// str = str + ''+data.attachmentName+'';
// }
// str = str +' | '+
// ''+data.createByName+' | '+
// ''+data.createDate+
// ''+
// ''+
// ''+
// ''+
// ''+
// ''+
// ''+
// ' | '+
// ''+
// '' +
// ' 下载'+
// ' 删除'+
// ' ' +
// ' | '+
// '
';
// console.log("file:"+divId);
// console.log("str="+str);
// $("#file"+divId).append(str);
// // $("img").not(".upload_ico").each(function () {
// // var num = 1 ;
// // $(this).live("click",function () {
// // var flag = num%2;
// // if(flag == 1){
// // $(this).css("width","90%");
// // $(this).css("height","90%");
// // num++;
// // }else if(flag ==0){
// // $(this).css("width","50px");
// // $(this).css("height","50px");
// // num++;
// // }
// // })
// // });
// }else {
// parent.layer.msg("上传失败!",{icon:2});
// }
// }
// })
// }).catch(function (err) {
// console.log("err------ err:");
// console.log(err);
// multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPath, size,checkpoint_temp);
// });
};
function isContains(str, substr) {
return str.indexOf(substr) >= 0;
}
function deleteFileFromAliyun(obj,deleteUrl,addFile,divId){
console.log("---------------------------------:");
console.log(divId);
console.log("---------------------------------");
if (divId==null || divId== undefined || divId == ''){
divId = "_attachment";
}
var fileDiv = divId.substr(1,divId.length)+"_file";
console.log("---------------------------------:");
console.log(fileDiv);
console.log("---------------------------------");
$("#"+fileDiv).val("");
$.ajax({
type:"post",
url:deleteUrl,
success:function(data){
if(data.str){
parent.layer.msg('删除成功',{icon:1});
$(obj).parent().parent().parent().remove();
$("#"+addFile).hide();
}else {
parent.layer.msg('删除失败',{icon:2});
}
}
});
}