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的超时时间!
MARK:
最近在关注一个手机挖矿项目,叫Bee蜜蜂币。
APP 下载链接: https://bee.com/sc/
推荐码:lei911gang
手机免费挖矿,感兴趣的可以一起加入。