kendo ui upload html + java + springmvc

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

页面:

<div class="demo-section k-content">
        <input name="files" id="files" type="file" />
</div>
JS:这里需要注意下,后台传递过来的数据kendoUI全部封装到了response(此response非彼response)里

<script>
                $(document).ready(function () {
                    $("#files").kendoUpload({
                        multiple: true,
                        async: {
                            saveUrl: "mcinfo/uploadDoc",
                            removeUrl: "mcinfo/removeDoc",
                            autoUpload: true
                        },
                        files: initialFiles,
                        success: onSuccess//上传成功回调,还有很多时间,不一一介绍
                    });
                    
                    function onSuccess(e) {
                        alert(JSON.stringify(e.response));//后台传递过来的数据全部封装在response中
                        // 这里根据自己的需要做处理
                    }
                });
 </script>

后台:

	/* 这个是用来请求的地址 */
        @RequestMapping(value = "/uploadDoc")
	@ResponseBody
	public Map<String, Object> uploadDoc(@RequestParam List<MultipartFile> files, @RequestParam String folder) throws FileNotFoundException, IOException{
		Map<String, Object> result = new HashMap<String, Object>();
		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上传就是这么简单

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值