Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.zg.common.utils;
|
package com.zg.common.utils;
|
||||||
|
|
||||||
|
import com.zg.framework.config.RuoYiConfig;
|
||||||
import io.minio.*;
|
import io.minio.*;
|
||||||
import io.minio.errors.*;
|
import io.minio.errors.*;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -7,7 +8,11 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,6 +97,27 @@ public class MinioUtil {
|
|||||||
|
|
||||||
return endpoint + "/" + bucketName + "/" + objectName;
|
return endpoint + "/" + bucketName + "/" + objectName;
|
||||||
}
|
}
|
||||||
|
public String uploadBase64(String imgStr,String bucketName,String folder){
|
||||||
|
try {
|
||||||
|
String objectName = folder + UUID.randomUUID().toString().replace("-", "") + ".png";
|
||||||
|
String filePath = RuoYiConfig.getProfile()+"/"+bucketName+"/"+objectName;
|
||||||
|
imgStr = imgStr.replace("data:image/png;base64,", "");
|
||||||
|
// 解码Base64字符串
|
||||||
|
byte[] imageBytes = Base64.getDecoder().decode(imgStr);
|
||||||
|
|
||||||
|
// 将字节转换为BufferedImage
|
||||||
|
BufferedImage img = javax.imageio.ImageIO.read(new java.io.ByteArrayInputStream(imageBytes));
|
||||||
|
|
||||||
|
// 写入图片到文件系统
|
||||||
|
File outputFile = new File(filePath);
|
||||||
|
ImageIO.write(img, "PNG", outputFile);
|
||||||
|
return endpoint + "/" + bucketName + "/" + objectName;
|
||||||
|
// System.out.println("图片已保存到: " + outputFile.getAbsolutePath());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("转换或保存图片时发生错误: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件到默认 bucket 根目录
|
* 上传文件到默认 bucket 根目录
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package com.zg.project.wisdom.controller;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.zg.common.exception.ServiceException;
|
import com.zg.common.exception.ServiceException;
|
||||||
import com.zg.common.utils.MinioUtil;
|
import com.zg.common.utils.MinioUtil;
|
||||||
import com.zg.common.utils.SecurityUtils;
|
import com.zg.common.utils.SecurityUtils;
|
||||||
@@ -52,7 +54,18 @@ public class AuditSignatureController extends BaseController
|
|||||||
return AjaxResult.error("上传失败: " + e.getMessage());
|
return AjaxResult.error("上传失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 上传图片,接收base64格式 zhangjinbo
|
||||||
|
@PostMapping("/uploadBase64")
|
||||||
|
public AjaxResult uploadSignatureBase64(@RequestBody Map<String, String> param) {
|
||||||
|
String imgStr = param.get("imgStr");
|
||||||
|
// return AjaxResult.success("上传成功").put("url", imgStr);
|
||||||
|
if (imgStr == null) {
|
||||||
|
return AjaxResult.error("上传文件不能为空");
|
||||||
|
}
|
||||||
|
String url = minioUtil.uploadBase64(imgStr, "jaz","signature/");
|
||||||
|
return AjaxResult.success("上传成功").put("url", url);
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询审批记录列表
|
* 查询审批记录列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user