kendo ui upload html + java + springmvc

kendo ui相关资料网上一直不好找,这里关于kendoUI上传文件记录一下,html + java + springmvc

页面:

JS:这里需要注意下,后台传递过来的数据kendoUI全部封装到了response(此response非彼response)里

后台:

	/* 这个是用来请求的地址 */
        @RequestMapping(value = "/uploadDoc")
	@ResponseBody
	public Map uploadDoc(@RequestParam List files, @RequestParam String folder) throws FileNotFoundException, IOException{
		Map result = new HashMap();
		String fileName = UUID.randomUUID() + ".jpg";
		if(StrUtil.isNull(folder)){
			folder = UUID.randomUUID().toString();
		}
		String uploadpath="E:/mcdoc/" + folder;
		for(MultipartFile file : files) {
	    	UploadFileUtil.fileUpload(file.getInputStream(), fileName, uploadpath);
    	}
		result.put("uploadpath", uploadpath);
		result.put("folder", folder);
		result.put("success", true);
		return result;
	}
这个是上传方法:

	/**
	 * 文件上传
	 * @param file
	 * @param filename
	 * @param upload_path
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	public static void fileUpload(InputStream in, String filename, String upload_path)
			throws FileNotFoundException, IOException {
		File uploadFolder = new File(upload_path);
		if (!uploadFolder.exists()) {
			uploadFolder.mkdir();
		}
		File uploadFile = new File(uploadFolder + "/" + filename);
		OutputStream out = new FileOutputStream(uploadFile);
		byte[] buffer = new byte[1024 * 1024];
		int length;
		while ((length = in.read(buffer)) > 0) {
			out.write(buffer, 0, length);
		}
		in.close();
		out.close();
	}
到此完毕,kendoUI上传就是这么简单

你可能感兴趣的:(kendo ui upload html + java + springmvc)