Eex代码
Ext.onReady(function() {
Ext.MultiUploadWindow = Ext.extend(Ext.Window, {
xtype : "window",
title : "图片上传",
id : "ext-win-swfupload",
width : 650,
height : 300,
modal : true,
closable : true,
resizable : false,
initComponent : function() {
gid = this.gid;
this.items = [{
xtype : "form",
id : "ext-form-upload",
labelAlign : "right",
layout : "column",
fileUpload : true,
height : 235,
frame : true,
items : [{
xtype:'uploadPanel',
border : false,
fileSize : 1024*50,//限制文件大小
uploadUrl : '../../../back/scGoodsDetailController.do?multiupload&gid='+gid,
flashUrl : '../../../js/upload/swfupload.swf',
filePostName : 'myUpload', //后台接收参数
fileTypes : '*.jpg;*.png;*.bmp',//可上传文件类型
file_types_description: "Web Image Files",
postParams : {savePath:'upload\\'} //上传文件存放目录
}
]}
];
this.buttons = [{
text : '关闭',
iconCls : 'cancel',
handler : function() {
Ext.getCmp('ext-win-swfupload').destroy();
store3.load({params:{start:0,limit:100,gid:gid}});
}
} ];
Ext.MultiUploadWindow.superclass.initComponent.call(this);
this.show();
}
});
});
java代码
@RequestMapping(params = "multiupload")
@ResponseBody
public AjaxJson multiupload(String gid, HttpServletRequest request, HttpServletResponse response) throws Exception{
//String msg = "";
AjaxJson j = new AjaxJson();
try{
ScGoodsDetail scGoodsDetail = new ScGoodsDetail();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("myUpload");
if (file.getSize() > 0) {
String filename = file.getOriginalFilename();
String path = SystemPath.getSysPath().replace("%20", " ") + "upload/goods/picture/";
String nm = java.util.UUID.randomUUID().toString();
String hz = FileUtils.getFileExtension(filename).toLowerCase();
if(!hz.equals("jpg")&&!hz.equals("png")&&!hz.equals("bmp")){
j.setMsg("只能上传jpg、png、bmp类型的图片");
j.setSuccess(false);
return j;
}
String localfilename = nm + "." + hz;
//String localfilename2 = nm + "2." + hz;
// 写入文件
File source = new File(path + localfilename);
file.transferTo(source);
//BufferedImage bufImage = ImageIO.read(new File(path + localfilename));
//int dwInW = bufImage.getWidth();
//int dwInH = bufImage.getHeight();
//slt(path + localfilename2, path + localfilename, hz, 750,519);
//source.delete();
scGoodsDetail.setPath(localfilename);
/*Thumbnails.of(path + localfilename)
.forceSize(500,200)
.toFile(path +"/small/"+ localfilename);*/
scGoodsDetail.setGid(gid);
j.setMsg(scGoodsDetailService.insert(scGoodsDetail));
}else{
j.setMsg("请选择图片!");
j.setSuccess(false);
return j;
}
}catch(Exception e){
j.setMsg(e.toString());
}
return j;
}