浏览代码

Merge branch 'master' of https://git.flowbb.cn/humuyu/appsp

humuyu 2 年之前
父节点
当前提交
1e8d854f12

+ 1 - 0
java/sp-app/src/main/resources/application.properties

@@ -140,3 +140,4 @@ sp.minio.accesskey=minioadmin
 sp.minio.secretkey=minioadmin
 sp.minio.url=http://124.222.192.60:9000
 sp.minio.bucketName=mytest
+sp.minio.preview=https://fqgz.flowbb.cn

+ 4 - 1
java/sp-auth/src/main/java/com/anji/sp/config/SecurityConfig.java

@@ -99,7 +99,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                   "/login/**",
                   "/phone/**", 
                   "/download/**", 
-                  "/upload/uploadMinio", 
+                  "/upload/uploadMinio",
+                  "/upload/uploadFaceImage",
+                  "/upload/getPreview",
+                  "/upload/getFile",
                   "/captcha/**").anonymous()
                 .antMatchers(
                         HttpMethod.GET,

+ 22 - 1
java/sp-version/src/main/java/com/anji/sp/controller/SpFileUploadController.java

@@ -1,5 +1,6 @@
 package com.anji.sp.controller;
 
+import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -7,6 +8,8 @@ import java.util.Objects;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -45,7 +48,7 @@ public class SpFileUploadController {
 
 	/**
 	 * 文件上传
-	 * 
+	 *
 	 * @param spUploadVO
 	 * @return
 	 */
@@ -103,4 +106,22 @@ public class SpFileUploadController {
 		map.put("msg", "操作成功!");
 		return map;
 	}
+
+	@RequestMapping("/uploadFaceImage")
+	public Map<String, Object> uploadFaceImage(@RequestBody String image) {
+		JSONObject json = JSONObject.parseObject(image);
+		String imagePath="";
+		try {
+			imagePath = FileUploadUtils.saveFaceImage(json.getString("base64"));
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		// SUCCESS(100,"操作成功!"),
+		Map<String, Object> map = new HashMap<>();
+		map.put("code", 100);
+		map.put("msg", "操作成功!");
+		map.put("imagePath",imagePath);
+		return map;
+	}
+
 }

+ 16 - 2
java/sp-version/src/main/java/com/anji/sp/service/impl/MinioFileHandle.java

@@ -5,6 +5,7 @@ import java.io.InputStream;
 
 import javax.annotation.PostConstruct;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationContext;
@@ -38,6 +39,11 @@ public class MinioFileHandle implements FileHandle,ApplicationContextAware {
 	@Value("${sp.minio.secretkey:minioadmin}")
 	public String appMinioSecretkey;
 
+	@Value("${sp.minio.preview:https://fqgz.flowbb.cn}")
+	protected String appMinioPreview;
+
+
+
 	private MinioClient minioClient;
 
 	@PostConstruct
@@ -131,8 +137,16 @@ public class MinioFileHandle implements FileHandle,ApplicationContextAware {
 
 	@Override
 	public String getPreviewUrl(String fileKey) throws Exception {
-		// TODO Auto-generated method stub
-		return null;
+		if (StringUtils.isNotBlank(fileKey) && (fileKey.startsWith("http") || fileKey.startsWith("https"))) {
+			return fileKey;
+		}
+		try {
+			String fileUrl = getObjectUrl(fileKey);
+			int index = fileUrl.indexOf("/", 8);
+			return appMinioPreview + fileUrl.substring(index);
+		} catch (Exception e) {
+			throw e;
+		}
 	}
 
 	@Override

+ 20 - 10
java/sp-version/src/main/java/com/anji/sp/util/file/FileUploadUtils.java

@@ -23,10 +23,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -223,7 +220,6 @@ public class FileUploadUtils {
 	}
 
 	public static String uuid() {
-
 		return UUID.randomUUID().toString().replace("-", "");
 	}
 
@@ -328,13 +324,28 @@ public class FileUploadUtils {
 	 * @param image 图片数据
 	 * @return
 	 */
-	public static String saveImage(byte[] b, String fileType) {
+	public static String saveFaceImage(String imgStr) {
 
+		if (imgStr == null) // 图像数据为空
+			return null;
 		try {
-
-			String suffix = getFormatName(b);
+			String suffix = imageFileSuffix(imgStr);
+			if (StringUtils.isNotEmpty(suffix)) {
+				// 去掉data:image/jpeg;这种类型的
+				String[] base64Prefix = imgStr.split("base64,");
+				if (base64Prefix != null && base64Prefix.length > 1) {
+					imgStr = base64Prefix[1];
+				}
+			}
+			// Base64解码
+			byte[] b = Base64.decodeBase64(imgStr);
+			for (int i = 0; i < b.length; ++i) {
+				if (b[i] < 0) {// 调整异常数据
+					b[i] += 256;
+				}
+			}
 			if (StringUtils.isEmpty(suffix)) {
-				suffix = fileType;
+				suffix = getFormatName(b);
 			}
 			// TODO 这里再判断,通过二进制,如果还是失败抛出异常,
 			// 如果不存在,创建文件夹
@@ -381,7 +392,6 @@ public class FileUploadUtils {
 			}
 
 		}
-
 	}
 
 	/**