标签:base 上传 new str base64 ram ring rand common
/**
* 图片上传
* @param imgBase
* @return
*/
@PostMapping("/upload")
public CommonResult upload(String imgBase){
byte[] b1 = null;
BASE64Decoder decoder = new BASE64Decoder();
try{
if (imgBase.indexOf("data:image/jpeg;base64,") != -1) {
b1 = decoder.decodeBuffer(imgBase.replaceAll("data:image/jpeg;base64,", ""));
} else {
if (imgBase.indexOf("data:image/png;base64,") != -1) {
b1 = decoder.decodeBuffer(imgBase.replaceAll("data:image/png;base64,", ""));
} else {
b1 = decoder.decodeBuffer(imgBase.replaceAll("data:image/jpg;base64,", ""));
}
}
for (int i = 0; i < b1.length; ++i) {
if (b1[i] < 0) {// 调整异常数据
b1[i] += 256;
}
}
}catch(Exception e){
e.printStackTrace();
}
//添加图片url;
String name = UUID.randomUUID().toString().replace("_", "");
try {
String upload = new QiniuUploadUtil().upload(name, b1);
System.out.println("uploaduploadupload"+upload);
if(imgUrl==null){
imgUrl=new ArrayList<>();
}
imgUrl.add(upload);
} catch (Exception e) {
e.printStackTrace();
}
return CommonResult.success("1");
}
}
标签:base 上传 new str base64 ram ring rand common
原文地址:https://www.cnblogs.com/xiaofengshan/p/12584159.html