...
 
Commits (2)
    https://gitcode.net/learnhub/minio/-/commit/71639af5f5266b1f5c344ab900622f518a8ba5de Update test case code 2023-02-16T15:20:48+08:00 hexiang hexiang@ygsoft.com https://gitcode.net/learnhub/minio/-/commit/6669319093020ebfbc96e4f1b9392a0f29bdbc49 update dependency 2023-02-16T15:50:51+08:00 hexiang hexiang@ygsoft.com
...@@ -40,17 +40,6 @@ ...@@ -40,17 +40,6 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
package com.example.demo.demos.controller; package com.example.demo.demos.controller;
import com.example.demo.demos.enums.FilePathType;
import com.example.demo.demos.result.Result; import com.example.demo.demos.result.Result;
import com.example.demo.demos.utils.MinIOUtil; import com.example.demo.demos.utils.MinIOUtil;
import com.example.demo.demos.utils.StringUtil;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -38,7 +40,7 @@ public class DemoController { ...@@ -38,7 +40,7 @@ public class DemoController {
@PostMapping("/upload") @PostMapping("/upload")
public Result upload(MultipartFile file) throws Exception { public Result upload(MultipartFile file) throws Exception {
// TODO 文件路径、文件夹名、文件名自定义设置处理 // TODO 文件路径、文件夹名、文件名自定义设置处理
String fileName = file.getOriginalFilename(); String fileName = FilePathType.VIDEO.PATH+StringUtil.getCurrentTimeStr()+"_"+file.getOriginalFilename();
// 通过文件流的方式上传文件,可自己开发其他上传方式 // 通过文件流的方式上传文件,可自己开发其他上传方式
MinIOUtil.uploadFile(fileName,file.getInputStream()); MinIOUtil.uploadFile(fileName,file.getInputStream());
// 获取文件上传成功的地址,如果获取其他文件信息,可自行封装对象 // 获取文件上传成功的地址,如果获取其他文件信息,可自行封装对象
...@@ -47,5 +49,4 @@ public class DemoController { ...@@ -47,5 +49,4 @@ public class DemoController {
return Result.ok(url); return Result.ok(url);
} }
} }
package com.example.demo.demos.enums;
/**
* 文件类型 枚举
*/
public enum FilePathType {
VIDEO(1, "video/"),
FACE(2, "image/");
public final Integer TYPE;
public final String PATH;
FilePathType(Integer type, String path) {
this.TYPE = type;
this.PATH = path;
}
}
package com.example.demo.demos.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
/**
* 字符串工具类
* @author hexiang
*/
public class StringUtil {
/**
* 判断是否为正确的手机号
* @param mobile 手机号
* @return isPhoneNumber
*/
public static boolean isPhoneNumber(String mobile){
return mobile.matches("^[1][3,4,5,7,8,9][0-9]{9}$");
}
/**
* 生成自定义UUid
*
* @param prefix 前缀
* @param length 长度
* @return 自定义UUid
*/
public static String getCustomUUid(String prefix, int length){
if(length>16) length = 16;
return prefix + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + UUID.randomUUID().toString().substring(0, length);
}
/**
* 生成当前时间搓字符
*/
public static String getCurrentTimeStr(){
return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
}
}