您的位置:首页 > 编程语言 > Java开发

springboot,feign上传超大文件,超时等问题解决方案

2017-12-29 15:07 2915 查看
1.在yml中配置文件上传大小限制

spring.http.multipart.maxFileSize: 200Mb
spring.http.multipart.maxRequestSize: 200Mb

2.controller中添加上传文件接口

@PostMapping(value = "/uploadImg")
// @HystrixCommand(fallbackMethod = "abc")
public HsResult uploadImg(@RequestParam("picFile") MultipartFile picFile) {
return this.mechanismInfoService.uploadImg(picFile);//具体上传逻辑可以自己实现
}


上传成功。

---------------------------------------------------------------------------------------

《feign调用上传接口方案》

1.同样配置yml

spring.http.multipart.maxFileSize: 200Mb
spring.http.multipart.maxRequestSize: 200Mb

2.编写feignservice

@Autowired
private FeignService feignService;
@PostMapping(value = "/up")
public HsResult up(@RequestParam("picFile") MultipartFile picFile) {
return this.feignService.uploadImg(picFile);
}


@Component
@FeignClient(value = "map-service")
public interface FeignService {
@RequestMapping(value = "/mechanism/uploadImg",method = RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public HsResult uploadImg(@RequestPart("picFile") MultipartFile picFile);


如果报超时错误,需要调大hystrix和ribbon的超时时间!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息