@RequestMapping(value ="/upload.do",method=RequestMethod.POST)
@ResponseBody
public Object UpLoadImg(@RequestParam(value="myFileName")MultipartFile[] mfs) {
List<Map<String, String>> data=new ArrayList<Map<String, String>>();
for (int i=0;i<mfs.length;i++){
MultipartFile mf= mfs[i];
String realPath = request.getSession().getServletContext().getRealPath("file/ueditor");
//获取源文件
String filename = mf.getOriginalFilename();
String[] names=filename.split("\\.");//
String tempNum=(int)(Math.random()*100000)+"";
String uploadFileName=tempNum +System.currentTimeMillis()+"."+names[names.length-1];
File targetFile = new File (realPath,uploadFileName);//目标文件
//开始从源文件拷贝到目标文件
//传图片一步到位
try {
mf.transferTo(targetFile);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Map<String, String> map = new HashMap<String, String>();
map.put("data","/file/ueditor/"+uploadFileName);//这里应该是项目路径
data.add(map);
}
return data;//将图片地址返回
}
实现多文件上传(2)
猜你喜欢
转载自blog.csdn.net/wuhuayangs/article/details/85772046
今日推荐
周排行