前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >上传图片接口

上传图片接口

作者头像
用户1220053
发布2018-02-09 10:26:38
3.6K0
发布2018-02-09 10:26:38
举报
文章被收录于专栏:DT乱“码”DT乱“码”
代码语言:javascript
复制
/**
	 *上传图片
	 * @param savePath
	 * @return
	 * @throws Exception
	 */
	public String saveImage(String savePath, File imagePath,String imagePathFileName)throws Exception{
		 StringBuffer sb = new StringBuffer();
		 String path = "";
		if(null != imagePath && !"".equals(imagePath)){
			sb.append(savePath);
			   SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
			   sb.append(simpleDateFormat.format(new Date()));
				String uploadPath = sb.toString(); 
				File uploadFile = new File(uploadPath);
				if(!uploadFile.exists()){
					uploadFile.mkdirs();  
				}
				String imageName = UUID.randomUUID().toString()+imagePathFileName.subSequence(imagePathFileName.lastIndexOf("."), imagePathFileName.length());
				imageName = imageName.replace("|", "_");
				File saveFile = new File(uploadFile, imageName);
				FileUtils.copyFile(imagePath, saveFile);
				path = sb.toString()+"/"+imageName;
		}
		if(StringUtils.isNotBlank(path)){
			path = path.replace(EopSetting.IMG_SAVE_PATH +"/statics", "");
			path = EopSetting.UPLOAD_IMG_SERVER_DOMAIN+ path;
		} 
		   
		logger.info("====upload image url : " + path);
		return path;
		
	}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档