feat(oss): 实现文件上传功能并集成Feign调用
- 新增文件上传接口,支持multipart/form-data格式 - 配置Spring Servlet multipart参数,设置文件大小限制 - 添加Feign客户端配置,支持表单提交 - 实现Feign请求拦截器,传递用户上下文信息 - 创建OSS服务API接口,用于文件上传 - 在用户服务中集成OSS RPC调用,实现头像和背景图上传 - 添加上传失败的业务异常处理 - 更新pom.xml依赖,引入OpenFeign、负载均衡及Feign表单相关组件 - 定义API常量和服务名称 - 启用Feign客户端扫描,支持跨服务调用
This commit is contained in:
@@ -20,5 +20,24 @@
|
||||
<groupId>com.hanserwei</groupId>
|
||||
<artifactId>hanserwei-common</artifactId>
|
||||
</dependency>
|
||||
<!-- OpenFeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- 负载均衡 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<!-- Feign 表单提交 -->
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign.form</groupId>
|
||||
<artifactId>feign-form-spring</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign.form</groupId>
|
||||
<artifactId>feign-form</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hanserwei.hannote.oss.api;
|
||||
|
||||
import com.hanserwei.framework.common.response.Response;
|
||||
import com.hanserwei.hannote.oss.config.FeignFormConfig;
|
||||
import com.hanserwei.hannote.oss.constant.ApiConstants;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@FeignClient(name = ApiConstants.SERVICE_NAME, configuration = FeignFormConfig.class)
|
||||
public interface FileFeignApi {
|
||||
|
||||
String PREFIX = "/file";
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 文件上传结果
|
||||
*/
|
||||
@PostMapping(value = PREFIX + "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
Response<?> uploadFile(@RequestPart(value = "file") MultipartFile file);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.hanserwei.hannote.oss.config;
|
||||
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class FeignFormConfig {
|
||||
|
||||
@Bean
|
||||
public Encoder feignFormEncoder() {
|
||||
return new SpringFormEncoder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hanserwei.hannote.oss.constant;
|
||||
|
||||
public interface ApiConstants {
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
String SERVICE_NAME = "han-note-oss";
|
||||
}
|
||||
Reference in New Issue
Block a user