Zuul上传文件
返回目录:https://blog.csdn.net/BW_Bear/article/details/88746646源码位置:微服务注册:https://github.com/zhaowei-zhang/CloudTest/tree/master/使用Zuul构建微服务网关/microservice-discovery-eureka上传微服务:https://github.com/z...
·
返回目录:
https://blog.csdn.net/BW_Bear/article/details/88746646
源码位置:
微服务注册:
https://github.com/zhaowei-zhang/CloudTest/tree/master/使用Zuul构建微服务网关/microservice-discovery-eureka
上传微服务:
网关:
https://github.com/zhaowei-zhang/CloudTest/tree/master/使用Zuul构建微服务网关/microservice-gateway-zuul
Zuul上传文件
1.创建文件上传微服务
1.1. 创建新项目,引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--Eureka client 依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
1.2.修改启动类
@EnableEurekaClient
1.3.编写上传controller
@Controller
public class FileUploadController {
@RequestMapping(value = "/upload",method = RequestMethod.POST)
public @ResponseBody String fileUpload(
@RequestParam(value = "file",required = true) MultipartFile file
) throws IOException {
byte[] bytes=file.getBytes();
File fileSave=new File(file.getOriginalFilename());
FileCopyUtils.copy(bytes,fileSave);
return fileSave.getAbsolutePath();
}
}
1.4.修改配置文件
server:
port: 9108
eureka:
client:
service-url:
defaultZone: http://localhost:9100/eureka/
instance:
prefer-ip-address: true
spring:
application:
name: microservice-file-upload
http:
multipart:
max-file-size: 200Mb
max-request-size: 250Mb
2. 测试
2.1 启动eureke、上传微服务、Zuul
2.2 直接上传小文件.成功
2.3 直接上传大文件。成功
2.4 通过Zuul上传小文件.成功
2.5 通过Zuul上传大文件添加.失败
2.6 通过Zuul上传大文件,添加/zuul前缀.失败(超时)
返回目录:
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献2条内容
所有评论(0)