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

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的超时时间!



你可能感兴趣的:(springboot,springcloud,zuul)