html
js
//自定义获取图片路径函数
function getObjectURL(file) {
}
function fileSelect(obj) {
}
function fileSelected(obj) {
var extName = "JPG,GIF,PNG,JPEG,BMP";
if(extName.indexOf(obj.files[0].name.substr(obj.files[0].name.lastIndexOf(".")+1).toUpperCase())<0)
{
$.showPop({
title: '',
content: "请选择正确的图片文件",
confirm: function(){
}
});
return false;
}
if(obj.files[0].size/1024>5120){
$.showPop({
title: '',
content: "请选择小于5M的图片",
confirm: function(){
}
});
return false;
}
var url = getObjectURL(obj.files[0]);
if(obj.id=='idCardf')
$('#idCardImgStr').attr('src',url).show();//展示图片
$.ajax({
async: false,
$('#idCardImg').val(data.message); $curretDiv.find("#idCardImg").parent().parent().find(".form_error").html(''); }
;
}else
},
error : function(data){ }
}
//后台实现
@ResponseBody
public ResponseBase addImg(@RequestParam MultipartFile idCardf) throws IOException {
final ResponseBase responseBase = new ResponseBase();
String suffix = idCardf.getOriginalFilename().toString();
String key = "funpic/template/"+suffix;
OSSClient sossClient = new OSSClient(this.endpoint, this.accessKeyId, this.accessKeySecret);
ObjectMetadata omt = new ObjectMetadata();
omt.setLastModified(new Date());
//上传照片
ossClient.putObject(this.bucketName, key,
new ByteArrayInputStream(
idCardf.getBytes()), omt);
return responseBase;
}
//上面的方法IE不支持
js:
}