|
|
@@ -62,7 +62,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
+import java.nio.file.Files;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Date;
|
|
|
@@ -238,6 +240,21 @@ public class StundentFaceProcessController {
|
|
|
byte[] imageBytes = outputStream.toByteArray();
|
|
|
//压缩到200k
|
|
|
imageBytes = ImageUtil.compressUnderSize(imageBytes, 204800);
|
|
|
+ //压缩之后,存入本地
|
|
|
+ String suffix = StringUtils.substringAfterLast(filename, StringPool.DOT);
|
|
|
+ String tempFilePath = "/" + IdUtil.getSnowflakeNextId() + "." + suffix;
|
|
|
+ FileOutputStream fos = new FileOutputStream(tempFilePath);
|
|
|
+ fos.write(imageBytes);
|
|
|
+ fos.close();
|
|
|
+ //再读取出来
|
|
|
+ java.io.File tempFile = new java.io.File(tempFilePath);
|
|
|
+ imageBytes = Files.readAllBytes(tempFile.toPath());
|
|
|
+
|
|
|
+ //删除文件
|
|
|
+ if(tempFile.exists()){
|
|
|
+ tempFile.delete();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
String base64String = Base64.getEncoder().encodeToString(imageBytes);
|
|
|
inputStream.close();
|
|
|
@@ -248,7 +265,7 @@ public class StundentFaceProcessController {
|
|
|
|
|
|
//存入数据库
|
|
|
long fileId = IdUtil.getSnowflakeNextId();
|
|
|
- String suffix = StringUtils.substringAfterLast(filename, StringPool.DOT);
|
|
|
+
|
|
|
Long folderId = IdWorker.getId();
|
|
|
File fileEntity = new File();
|
|
|
fileEntity.setId(fileId);
|