分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

上传文件

发布时间:2023-09-06 01:23责任编辑:赖小花关键词:暂无标签
@RequestMapping("/uploadImage")@ResponseBody // 这里upfile是config.json中图片提交的表单名称public Map<String, String> uploadImage(@RequestParam("upfile") CommonsMultipartFile upfile,HttpServletRequest request) throws IOException {// 文件原名称String fileName = upfile.getOriginalFilename();SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");String formatDay = simpleDateFormat.format(new Date());// 为了避免重复简单处理String nowName = formatDay + "_"+new Date().getTime() + "_" + fileName;if (!upfile.isEmpty()) {String ueditorImagePath = PropertyUtil.readValue(Const.ueditorImagePath);// 上传位置路径String path0 = ueditorImagePath + "/" +formatDay+"/"+ nowName;// 按照路径新建文件java.io.File newFile = new java.io.File(path0);java.io.File newFile1 = new java.io.File(ueditorImagePath+ "/" +formatDay);if (!newFile1.exists()){boolean mkdir = newFile1.mkdirs();}// 复制FileCopyUtils.copy(upfile.getBytes(), newFile);}// 返回结果信息(UEditor需要)Map<String, String> map = new HashMap<String, String>();// 是否上传成功map.put("state", "SUCCESS");// 现在文件名称map.put("title", nowName);// 文件原名称map.put("original", fileName);// 文件类型 .+后缀名map.put("type", fileName.substring(upfile.getOriginalFilename().lastIndexOf(".")));// 文件路径map.put("url", "/kentra/file/getImage.do?imgName="+nowName);// 文件大小(字节数)map.put("size", upfile.getSize() + "");return map;}


本文出自 “JianBo” 博客,请务必保留此出处http://jianboli.blog.51cto.com/12075002/1980250

上传文件

原文地址:http://jianboli.blog.51cto.com/12075002/1980250

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved