Ver Fonte

上传图片的接口 获取图片url的接口

tongfeng há 3 anos atrás
pai
commit
a5d96247f6

+ 19 - 4
java/sp-version/src/main/java/com/anji/sp/util/file/FileUploadUtils.java

@@ -328,13 +328,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 这里再判断,通过二进制,如果还是失败抛出异常,
 			// 如果不存在,创建文件夹