Explorar el Código

update 底照大小限制

deason hace 2 años
padre
commit
02cfa4e3d7

+ 10 - 2
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/controller/FaceController.java

@@ -27,7 +27,7 @@ import cn.com.qmth.examcloud.web.support.ControllerSupport;
 
 /**
  * 人脸 处理
- * 
+ *
  * @author chenken
  * @date 2018年4月3日 下午3:58:31
  * @company QMTH
@@ -77,6 +77,12 @@ public class FaceController extends ControllerSupport {
 		if (!fileName.matches("[^\\.\\s]+\\.[^\\.\\s]+")) {
 			throw new StatusException("600101", "文件名不合法");
 		}
+
+		// 文件大小限制
+		if (file.getSize() > MAX_SIZE  * 1024) {
+			throw new StatusException("620005", "图片大小超过500KB");
+		}
+
 		String identityNumber = fileName.substring(0, fileName.lastIndexOf("."));
 		String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
 
@@ -106,6 +112,7 @@ public class FaceController extends ControllerSupport {
 		if (!filename.endsWith(".zip")) {
 			throw new StatusException("620001", "文件格式不正确,必须是zip格式的压缩包");
 		}
+
 		// 文件大小限制
 		if (file.getSize() > ZIP_MAX_SIZE * 1024 * 1024) {
 			throw new StatusException("620002", "文件大小超过50M,请分批导入");
@@ -135,10 +142,11 @@ public class FaceController extends ControllerSupport {
 
 			if (f.length() > MAX_SIZE * 1024) {
 				map.put("statusCode", "EX-620005");
-				map.put("statusDesc", "文件大小超过500KB");
+				map.put("statusDesc", "图片大小超过500KB");
 				ret.add(map);
 				continue;
 			}
+
 			try {
 				if (StringUtils.containsWhitespace(fileName)) {
 					throw new StatusException("600100", "文件名不能含有空白字符");

+ 13 - 5
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/FaceOuterServiceProvider.java

@@ -73,20 +73,20 @@ public class FaceOuterServiceProvider extends ControllerSupport implements FaceO
 		}
 
 		if (photoUrl.startsWith("http")) {
-			byte[] bs = HttpClientUtil.get(photoUrl);
-
 			int lastIndexOf = photoUrl.lastIndexOf(".");
 			if (0 > lastIndexOf) {
-				throw new StatusException("100002",
-						"photoPath is not end with photo file suffix.");
+				throw new StatusException("100002", "photoPath is not end with photo file suffix.");
 			}
-			String fileSuffix = photoUrl.substring(lastIndexOf);
 
+			String fileSuffix = photoUrl.substring(lastIndexOf);
 			String fileName = System.currentTimeMillis() + fileSuffix;
 			File temp = new File(systemConfig.getTempDataDir() + File.separator + "student_photo"
 					+ File.separator + fileName);
 
 			try {
+				// 文件大小限制
+				byte[] bs = HttpClientUtil.get(photoUrl, MAX_SIZE  * 1024);
+
 				FileUtils.writeByteArrayToFile(temp, bs);
 			} catch (IOException e) {
 				throw new StatusException("100003", "文件读写失败");
@@ -121,6 +121,12 @@ public class FaceOuterServiceProvider extends ControllerSupport implements FaceO
 		if (!fileName.matches("[^\\.\\s]+\\.[^\\.\\s]+")) {
 			throw new StatusException("600101", "文件名不合法");
 		}
+
+		// 文件大小限制
+		if (file.getSize() > MAX_SIZE  * 1024) {
+			throw new StatusException("620005", "图片大小超过500KB");
+		}
+
 		String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
 
 		faceService.processFace(rootOrgId, identityNumber, fileSuffix, storeLocation, operator);
@@ -145,6 +151,7 @@ public class FaceOuterServiceProvider extends ControllerSupport implements FaceO
 		if (!filename.endsWith(".zip")) {
 			throw new StatusException("620001", "文件格式不正确,必须是zip格式的压缩包");
 		}
+
 		// 文件大小限制
 		if (file.getSize() > ZIP_MAX_SIZE * 1024 * 1024) {
 			throw new StatusException("620002", "文件大小超过50M,请分批导入");
@@ -178,6 +185,7 @@ public class FaceOuterServiceProvider extends ControllerSupport implements FaceO
 				ret.add(map);
 				continue;
 			}
+
 			try {
 				if (StringUtils.containsWhitespace(fileName)) {
 					throw new StatusException("600100", "文件名不能含有空白字符");

+ 3 - 3
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/StudentOuterServiceProvider.java

@@ -120,19 +120,19 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
 			String operator) {
 
 		if (StringUtils.isNotBlank(photoUrl)) {
-			byte[] bs = HttpClientUtil.get(photoUrl);
-
 			int lastIndexOf = photoUrl.lastIndexOf(".");
 			if (0 > lastIndexOf) {
 				throw new StatusException("100002", "photoPath is not end with photo file suffix.");
 			}
-			String fileSuffix = photoUrl.substring(lastIndexOf);
 
+			String fileSuffix = photoUrl.substring(lastIndexOf);
 			String fileName = System.currentTimeMillis() + fileSuffix;
 			File temp = new File(systemConfig.getTempDataDir() + File.separator + "student_photo"
 					+ File.separator + fileName);
 
 			try {
+				byte[] bs = HttpClientUtil.get(photoUrl);
+
 				FileUtils.writeByteArrayToFile(temp, bs);
 			} catch (IOException e) {
 				try {

+ 8 - 8
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/cug/CugOuterServiceProvider.java

@@ -110,23 +110,23 @@ public class CugOuterServiceProvider extends ControllerSupport implements CugOut
 
 		String photoUrl = req.getPhotoUrl();
 		if (StringUtils.isNotBlank(photoUrl)) {
-			byte[] bs;
-			try {
-				bs = HttpClientUtil.get(photoUrl);
-			} catch (Exception e) {
-				throw new StatusException("100002", "photoUrl is wrong");
-			}
-
 			int lastIndexOf = photoUrl.lastIndexOf(".");
 			if (0 > lastIndexOf) {
 				throw new StatusException("100002", "photoPath is not end with photo file suffix.");
 			}
-			String fileSuffix = photoUrl.substring(lastIndexOf);
 
+			String fileSuffix = photoUrl.substring(lastIndexOf);
 			String fileName = identityNumber + fileSuffix;
 			File temp = new File(systemConfig.getTempDataDir() + File.separator + "student_photo"
 					+ File.separator + fileName);
 
+			byte[] bs;
+			try {
+				bs = HttpClientUtil.get(photoUrl);
+			} catch (Exception e) {
+				throw new StatusException("100002", "photoUrl is wrong");
+			}
+
 			try {
 				FileUtils.writeByteArrayToFile(temp, bs);
 			} catch (IOException e) {