瀏覽代碼

获取人脸比对图片文件

tongfeng 3 年之前
父節點
當前提交
8dc3d20887

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

@@ -102,6 +102,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                   "/upload/uploadMinio",
                   "/upload/uploadFaceImage",
                   "/upload/getPreview",
+                  "/upload/getFile",
                   "/captcha/**").anonymous()
                 .antMatchers(
                         HttpMethod.GET,

+ 28 - 0
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;
@@ -138,5 +141,30 @@ public class SpFileUploadController {
 		return map;
 	}
 
+	@RequestMapping("/getFile")
+	public Map<String,Object> getFile(@RequestBody String fileKey){
+		JSONObject json = JSONObject.parseObject(fileKey);
+		File file = null;
+		try {
+			file = FileUploadUtils.getFileWithPath(json.getString("fileKey"));
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+		ObjectMapper mapper = new ObjectMapper();
+		String s = null;
+		try {
+			s = mapper.writeValueAsString(file);
+		} catch (JsonProcessingException e) {
+			throw new RuntimeException(e);
+		}
+		Map<String, Object> map = new HashMap<>();
+		map.put("code", 100);
+		map.put("msg", "操作成功!");
+		map.put("file",s);
+		return map;
+	}
+
+
+
 
 }

+ 16 - 4
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;
@@ -405,7 +402,22 @@ public class FileUploadUtils {
 			}
 
 		}
+	}
+
 
+	public static File getFileWithPath(String filePath) throws Exception {
+		InputStream inputStream = fileHandle.getObject(filePath);
+		File file = File.createTempFile("compare",".jpeg");
+		file.deleteOnExit();
+		OutputStream outputStream = new FileOutputStream(file);
+		int bytesRead = 0;
+		byte[] buffer = new byte[8192];
+		while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
+			outputStream.write(buffer, 0, bytesRead);
+		}
+		inputStream.close();
+		outputStream.close();
+		return file;
 	}
 
 	/**