服务端已经可以实现,我想在客户端上传时就改变图片比例,减少传输压力。 下面是前台JS代码 不懂怎么处理
//文件上传
function upload(){
var exts = "jepg,jpg";
var fileType = "all",fileNum = "one";
new AjaxUpload("codeType-1",{
action: _ContextPath +'/sys/uploadFile.do?ajaxImgUpload',
name: 'file',
onSubmit : function(file, ext){
//验证上传文件格式 if(!validateExt(ext,exts)){
$.messager.alert("提示", "上传格式不符,上传格式为("+exts+")", "error");
return false;
}
if(fileNum != 'more'){ // 即fileNum == "one" 上传多个文件
this.disable();
}
this.setData({
module: "<%=FileUploadVO.MODULE_DEMO%>"
});
},
onComplete: function(file, response){
this.enable();
//返回结果处理
var operInfo = null;
try{
alert("aaaa"+response);
operInfo = eval('(' + response + ')');
} catch(e){}
if (operInfo){
if(operInfo.isOk) {
$.messager.alert("提示", "上传文件成功!", "info");
} else {
$.messager.alert("提示", operInfo.info, "error");
}
} else {
alert("bbbb");
$.messager.alert("提示", "上传失败!上传文件大小不超过31M", "error");
}
}
});
}
//文件上传
function upload(){
var exts = "jepg,jpg";
var fileType = "all",fileNum = "one";
new AjaxUpload("codeType-1",{
action: _ContextPath +'/sys/uploadFile.do?ajaxImgUpload',
name: 'file',
onSubmit : function(file, ext){
//验证上传文件格式 if(!validateExt(ext,exts)){
$.messager.alert("提示", "上传格式不符,上传格式为("+exts+")", "error");
return false;
}
if(fileNum != 'more'){ // 即fileNum == "one" 上传多个文件
this.disable();
}
this.setData({
module: "<%=FileUploadVO.MODULE_DEMO%>"
});
},
onComplete: function(file, response){
this.enable();
//返回结果处理
var operInfo = null;
try{
alert("aaaa"+response);
operInfo = eval('(' + response + ')');
} catch(e){}
if (operInfo){
if(operInfo.isOk) {
$.messager.alert("提示", "上传文件成功!", "info");
} else {
$.messager.alert("提示", operInfo.info, "error");
}
} else {
alert("bbbb");
$.messager.alert("提示", "上传失败!上传文件大小不超过31M", "error");
}
}
});
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货