将字符串中的64编码转成图片,上传阿里云
来源:互联网 发布:gdi高级编程 pdf 编辑:程序博客网 时间:2024/03/29 06:41
/**
* 将字符串中的64编码转成图片,上传阿里云
* @return
*/
public static String handleBase64ToImg(String content,String id){
content = content.replaceAll("<!--(.*?)-->", "");//删除内容体中的注释
String url = null;
Pattern p = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>",Pattern.CASE_INSENSITIVE);
String contentStr = StringEscapeUtils.unescapeJavaScript(content);
Matcher m = p.matcher(contentStr);
List<String> srcList = new ArrayList<String>();
while (m.find()) {
url = m.group(1);//去正则中的第一组数据
if(srcList.contains(url)){//排除重复的数据
continue;
}
srcList.add(url);
}
// 对字节数组字符串进行Base64解码并生成图片
if (CollectionUtils.isEmpty(srcList)){// 图像数据为空
return content;
} else {
BASE64Decoder decoder = new BASE64Decoder();
for(int i = 0;i < srcList.size();i++){
try {
// Base64解码 srcList.get(0).split(",")[1] customTopicImage
byte[] imgStream = decoder.decodeBuffer(srcList.get(i).split(",")[1]);//data:image/octet-stream;base64,iVBORw0KG ","后为正式的流数据
Long fileSize = (long) imgStream.length;//图片文件大小
/*for (int j = 0; j < b.length; ++j) {
if (imgStream[j] < 0) {// 调整异常数据
imgStream[j] += 256;
}
}*/
// 生成jpeg图片
//String imgFilePath = "d://"+id+"_"+i+".jpg";// 新生成的图片
//content = content.replace(fileSteam, "http://customTopicImageName//customTopicImage//"+id+"_"+i+".jpg");
String imgUrl = "http://abcd3.oss-cn-hangzhou.aliyuncs.com/";
String key = "customTopicImage/"+id+"_"+i+".jpg";
content = content.replace(srcList.get(i), imgUrl+key);
OSSUtils.putObjectBySteam(createParam(),imgStream ,key );
/*OutputStream out = new FileOutputStream(imgFilePath);
out.write(imgStream);
out.flush();
out.close();*/
} catch (Exception e) {
return content;
}
}
}
return content;
}
0 0
- 将字符串中的64编码转成图片,上传阿里云
- android将图片转成字符串,再将字符串转成图片
- android将图片转成字符串,再将字符串转成图片
- android将图片转成字符串,再将字符串转成图片
- 将ISO8859-1字符串转成GB2312编码
- android将图片转成字符串,再将字符串转成图片 (base64处理的字符串)
- php 将图片文件转成base64编码的方法
- iOS 阿里云上传图片
- 上传图片到阿里云
- 将Excel中的图片URL地址转成图片文件
- 图片转成base64编码
- 图片转成base64编码
- 将URL中的UTF-8字符串转成中文字符串
- 图片转成字符串喝字符串转成图片
- 将图片转成base64
- 将字符串转成列
- 将字符串转成十六进制
- 阿里云OSS上传图片,图片处理
- 提高iOS开发效率的方法和工具
- jQuery 插件开发
- IOS 读取本地plist类型文件数据
- 预防肾脏病
- day14
- 将字符串中的64编码转成图片,上传阿里云
- day15
- Win10正式版登陆界面的修改
- Java回调函数
- PAT (Advanced Level) 1084. Broken Keyboard (20) 坏键盘,字符串处理
- dialog.setCancelable(true);
- 移动开发-Android-tab效果之Fragment-1
- ios8 UITableViewCell 线条如何设置
- JAVA代码获取月份的第一天跟最后一天