后台代码
@RequestMapping("/fileUpload.do")
public void uploadFiles(@RequestParam MultipartFile file, HttpServletRequest request, HttpServletResponse response){
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/upload/");
String originalFilename = file.getOriginalFilename();
String pathname = realPath + "\\"+originalFilename;
FileUtils.copyInputStreamToFile(inputStream,new File(pathname));
System.out.println("sucess !");
} catch (IOException e) {
e.printStackTrace();
}
try {
response.getWriter().write("{\"code\":200}");
} catch (IOException e) {
e.printStackTrace();
}
}
upload.js文件中需要修改的地方
uploader = WebUploader.create({
pick: {
id: ‘#filePicker’,
label: ‘点击选择图片’
},
formData: {
uid: 123
},
dnd: ‘#dndArea’,
paste: ‘#uploader’,
swf: ‘image-upload/Uploader.swf’,
chunked: false,
chunkSize: 512 * 1024,
server: ‘/fileUpload.do’,//改成自己服务器的链接
// runtimeOrder: ‘flash’,
// accept: {
// title: 'Images',
// extensions: 'gif,jpg,jpeg,bmp,png',
// mimeTypes: 'image/*'
// },
// 禁掉全局的拖拽功能。这样不会出现图片拖进页面的时候,把图片打开。
disableGlobalDnd: true,
fileNumLimit: 300,
fileSizeLimit: 200 * 1024 * 1024, // 200 M
fileSingleSizeLimit: 50 * 1024 * 1024 // 50 M
});