Spring webflux MultipartFile方式上传文件报错

 时间:2024-10-14 00:41:06

Spring webflux通过MultipartFile方式上传文件报错的解决办法,代码示例

代码及示例:

1、以下是错误代码:@PostMapping( consumes = MediaType.MULTIPART_FORM_DATA_VALUE )public Mono<Void> save(@RequestPart("file")MultipartFile file) { log.info("Storing a new file. Recieved by Controller"); this.storageService.store(file);//保存文件的方法,请自己实现 return Mono.empty();}

2、上述代码会报错如下:org.springframework.web.server.UnsupportedMediaTypeStatusException: Response status 415 with reason "Content type 'image/png' not supported"

3、正确的方式是:使用@RequestPart("file") Mono<FilePart> file或者@R髫潋啜缅equestPart("file") Flux<FilePart>替换@RequestPart("file") MultipartFile file如下为正确代码:@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Mono<Void> save(@RequestPart("file") Mono<FilePart> file) { log.info("Storing a new file. Recieved by Controller"); this.storageService.store(file); //保存文件的方法,请自己实现 return Mono.empty(); }

  • 怎么安装静态测试工具QAC
  • Word2016中如何合并两个word文档
  • 怎么保鲜才让鱼眼不发白
  • 电脑浏览器如何全屏模式切换及添加书签?
  • Windows7操作系统开启cookie方法
  • 热门搜索
    小学生元旦手抄报 关爱教育手抄报 安全的手抄报内容 孝德手抄报 食品卫生安全手抄报 读书节的手抄报 飞向太空手抄报 足球手抄报 预防疾病手抄报内容 元旦节手抄报图片