zuul网关上传文件
在zuul网关工程加入实现上传功能的逻辑:
@RestController
public class UploadController {
@PostMapping(value = "/upload")
public String upload(@RequestParam(value = "file", required = true) MultipartFile file)
throws IOException {
byte[] bytes = file.getBytes();
File saveFile = new File(file.getOriginalFilename());
FileCopyUtils.copy(bytes, saveFile);
return saveFile.getAbsolutePath();
}
}
配置application.yml
spring:
application:
name: rpc-zuul
servlet:
multipart:
enabled: true
max-file-size: 10000000 # 最大单个文件大小
file-size-threshold: 1000 # 文件写入磁盘的阈值,当上传文件达到 1M 事开始写入磁盘
location: / # 上传文件的临时位置
上传访问地址:http://localhost:2001/upload
上传成功,但是中文乱码!!!
中文乱码解决方案
网上说在原有的上传访问路径上前加/zuul
,即变成访问http://localhost/zuul/upload
可是为毛我没有成功,日志还报错: No route found for uri: /zuul/upload