1. 程式人生 > >springboot,feign上傳超大檔案,超時等問題解決方案

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的超時時間!