/** * 图片上传 * @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"); }}
原文地址:https://www.cnblogs.com/xiaofengshan/p/12584159.html
时间: 2024-10-17 01:50:21