|
@@ -81,6 +81,9 @@ import javax.imageio.stream.ImageOutputStream;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -3529,7 +3532,7 @@ public class ApiController {
|
|
|
* @return R(/ admin / bucketName / filename)
|
|
|
*/
|
|
|
@PostMapping("/file/upload/mobile")
|
|
|
- public R uploadForMobile(@RequestParam("file") MultipartFile file) {
|
|
|
+ public R uploadForMobile(@RequestParam("file") MultipartFile file) throws IOException, NoSuchAlgorithmException {
|
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
|
@@ -3546,7 +3549,16 @@ public class ApiController {
|
|
|
return R.failed("无法获取用户id");
|
|
|
}
|
|
|
Integer id = user.getId();
|
|
|
- Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(String.format("%s:%s", id, originalFilename), IdUtil.fastSimpleUUID(), 7, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ // 文件md5
|
|
|
+
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
|
+ byte[] digest = md5.digest(bytes);
|
|
|
+ String hash = new BigInteger(1, digest).toString(16);
|
|
|
+
|
|
|
+
|
|
|
+ Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(String.format("%s:%s", id, hash), originalFilename, 7, TimeUnit.DAYS);
|
|
|
|
|
|
if (aBoolean != null && !aBoolean){
|
|
|
return R.failed("请勿上传重复的文件");
|