1.添加头像上传接口
This commit is contained in:
BIN
.idea/.cache/.Apifox_Helper/.toolWindow.db
generated
BIN
.idea/.cache/.Apifox_Helper/.toolWindow.db
generated
Binary file not shown.
14
pom.xml
14
pom.xml
@@ -156,8 +156,18 @@
|
|||||||
<artifactId>javase</artifactId>
|
<artifactId>javase</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 引入本项目 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dromara.x-file-storage</groupId>
|
||||||
|
<artifactId>x-file-storage-spring</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 引入 腾讯云 COS SDK,如果使用其它存储平台,就引入对应的 SDK -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qcloud</groupId>
|
||||||
|
<artifactId>cos_api</artifactId>
|
||||||
|
<version>5.6.227</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package vvpkassistant;
|
package vvpkassistant;
|
||||||
|
import org.dromara.x.file.storage.spring.EnableFileStorage;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
|
@EnableFileStorage
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ public class UserController {
|
|||||||
return ResponseData.success(userService.addUserWithMail(model));
|
return ResponseData.success(userService.addUserWithMail(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/activateAccount")
|
@GetMapping("/activate")
|
||||||
public ResponseData<Object> activateAccount(@RequestParam("token") String token){
|
public ResponseData<Object> activateAccount(@RequestParam("token") String token){
|
||||||
return ResponseData.success(userService.activateAccount(token));
|
return ResponseData.success(userService.activateAccount(token));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package vvpkassistant.file.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import vvpkassistant.Data.ResponseData;
|
||||||
|
import vvpkassistant.file.service.FileService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2025/8/7 13:58
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("file")
|
||||||
|
public class FileController {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/uploadHeadIcon")
|
||||||
|
public ResponseData<Object> uploadHeadIcon(@RequestParam("file") MultipartFile file) {
|
||||||
|
return ResponseData.success(fileService.uploadHeadIcon(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
src/main/java/vvpkassistant/file/service/FileService.java
Normal file
11
src/main/java/vvpkassistant/file/service/FileService.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package vvpkassistant.file.service;
|
||||||
|
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2025/8/7 13:58
|
||||||
|
*/
|
||||||
|
public interface FileService {
|
||||||
|
Object uploadHeadIcon(MultipartFile file);
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package vvpkassistant.file.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.UUID;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.x.file.storage.core.FileInfo;
|
||||||
|
import org.dromara.x.file.storage.core.FileStorageService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2025/8/7 13:58
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileStorageService fileStorageService;//注入实列
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object uploadHeadIcon(MultipartFile file) {
|
||||||
|
// 生成 UUID 文件名,保留原扩展名
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String extension = originalFilename != null && originalFilename.contains(".")
|
||||||
|
? originalFilename.substring(originalFilename.lastIndexOf("."))
|
||||||
|
: "";
|
||||||
|
String uuidFileName = UUID.randomUUID().toString().replace("-", "") + extension;
|
||||||
|
|
||||||
|
// 使用 fileStorageService 进行上传
|
||||||
|
// 设置保存的文件名为 UUID
|
||||||
|
|
||||||
|
// 返回文件信息或 URL
|
||||||
|
|
||||||
|
log.info("Uploading head icon to file: {}", uuidFileName);
|
||||||
|
return fileStorageService.of(file)
|
||||||
|
.setSaveFilename(uuidFileName) // 设置保存的文件名为 UUID
|
||||||
|
.upload();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,3 +45,18 @@ sa-token:
|
|||||||
activateUrl: http://192.168.1.174:8086/user/activate?token=
|
activateUrl: http://192.168.1.174:8086/user/activate?token=
|
||||||
verificationMailUrl: http://192.168.1.174:8086/user/verification?token=
|
verificationMailUrl: http://192.168.1.174:8086/user/verification?token=
|
||||||
forgetPassWordUrl: http://192.168.1.174:8086/user//resetPassword/?token=
|
forgetPassWordUrl: http://192.168.1.174:8086/user//resetPassword/?token=
|
||||||
|
|
||||||
|
dromara:
|
||||||
|
x-file-storage: #文件存储配置
|
||||||
|
default-platform: tencent-cos-1 #默认使用的存储平台
|
||||||
|
thumbnail-suffix: ".min.jpg" #缩略图后缀,例如【.min.jpg】【.png】
|
||||||
|
tencent-cos:
|
||||||
|
- platform: tencent-cos-1 # 存储平台标识
|
||||||
|
enable-storage: true # 启用存储
|
||||||
|
secret-id: AKIDNbcQ1c3HJD9rQ6g5PaZN0PekcIkyzmMl
|
||||||
|
secret-key: Nl4FI9mLo46vWu40iT0JQK8j8LK5cw2u
|
||||||
|
region: ap-shanghai #存仓库所在地域
|
||||||
|
bucket-name: vv-1317974657
|
||||||
|
domain: https://vv-1317974657.cos.ap-shanghai.myqcloud.com # 访问域名,注意“/”结尾,例如:https://abc.cos.ap-nanjing.myqcloud.com/
|
||||||
|
base-path: /headerIcon/ # 基础路径
|
||||||
|
|
||||||
|
|||||||
@@ -45,3 +45,18 @@ sa-token:
|
|||||||
activateUrl: http://192.168.1.174:8086/user/activate?token=
|
activateUrl: http://192.168.1.174:8086/user/activate?token=
|
||||||
verificationMailUrl: http://192.168.1.174:8086/user/verification?token=
|
verificationMailUrl: http://192.168.1.174:8086/user/verification?token=
|
||||||
forgetPassWordUrl: http://192.168.1.174:8086/user//resetPassword/?token=
|
forgetPassWordUrl: http://192.168.1.174:8086/user//resetPassword/?token=
|
||||||
|
|
||||||
|
dromara:
|
||||||
|
x-file-storage: #文件存储配置
|
||||||
|
default-platform: tencent-cos-1 #默认使用的存储平台
|
||||||
|
thumbnail-suffix: ".min.jpg" #缩略图后缀,例如【.min.jpg】【.png】
|
||||||
|
tencent-cos:
|
||||||
|
- platform: tencent-cos-1 # 存储平台标识
|
||||||
|
enable-storage: true # 启用存储
|
||||||
|
secret-id: AKIDNbcQ1c3HJD9rQ6g5PaZN0PekcIkyzmMl
|
||||||
|
secret-key: Nl4FI9mLo46vWu40iT0JQK8j8LK5cw2u
|
||||||
|
region: ap-shanghai #存仓库所在地域
|
||||||
|
bucket-name: vv-1317974657
|
||||||
|
domain: https://vv-1317974657.cos.ap-shanghai.myqcloud.com # 访问域名,注意“/”结尾,例如:https://abc.cos.ap-nanjing.myqcloud.com/
|
||||||
|
base-path: /headerIcon/ # 基础路径
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user