[英]no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data]
I an trying to integrate a file upload service, which is registered with a Eureka discovery infrastructure.我试图集成一个文件上传服务,该服务已在 Eureka 发现基础设施中注册。
My Service, say /myfile/upload is having below 6 parameters, below is the YML:我的服务,说 /myfile/upload 有以下 6 个参数,下面是 YML:
/myfile/upload:
put:
operationId: "uploadUsingPUT"
consumes:
- "multipart/form-data"
produces:
- "*/*"
parameters:
- name: "file"
in: "formData"
required: true
type: "file"
- name: "filename"
in: "formData"
required: true
type: "string"
- name: "path"
in: "formData"
required: true
type: "string"
- name: "header1"
in: "header"
required: true
type: "string"
- name: "header2"
in: "header"
required: false
type: "string"
allowEmptyValue: true
responses:
200:
description: "OK"
400:
description: "Bad Request"
I have created a client interface for this service, below is the API that I created:我为此服务创建了一个客户端接口,下面是我创建的 API:
import java.io.File;
import java.util.Map;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
@org.springframework.cloud.netflix.feign.FeignClient(value = "SERVICE-NAME", configuration = {
com.MyConfiguration.class})
public interface UploadControllerAPINew extends ApiClient.Api {
@RequestMapping(value = "/myfile/upload",
method = RequestMethod.PUT,
produces = "*/*",
consumes = "multipart/form-data"
)
FileUploadResponse uploadUsingPUT(@RequestPart("file") File file,
@RequestParam("filename") String filename, @RequestParam("path") String path,
@RequestHeader("header1") String header1,
@RequestHeader("header2") String header2);
@RequestMapping(value = "/myfile/upload",
method = RequestMethod.PUT,
produces = "*/*",
consumes = "multipart/form-data"
)
FileUploadResponse uploadUsingPUT1(@RequestBody Map<String, ?> formParams,
@RequestHeader("header1") String header1,
@RequestHeader("header2") String header2);
@RequestMapping(value = "/myfile/upload",
method = RequestMethod.PUT,
produces = "*/*",
consumes = "multipart/form-data"
)
FileUploadResponse uploadUsingPUT2(@RequestPart("file") byte[] file,
@RequestParam("filename") String filename, @RequestParam("path") String path,
@RequestHeader("header1") String header1,
@RequestHeader("header2") String header2);
}
to provide it with an encoder, I have added below encoder:为了给它提供一个编码器,我在下面添加了编码器:
@Bean
public Encoder feignEncoder() {
ObjectFactory<HttpMessageConverters> objectFactory = () ->
new HttpMessageConverters(new FormHttpMessageConverter());
// return new SpringEncoder(objectFactory);
return new FormEncoder(new SpringEncoder(objectFactory));
}
still I am getting exceptions with all the three approaches:我仍然遇到所有三种方法的例外情况:
uploadUsingPUT:上传使用PUT:
Could not write request: no suitable HttpMessageConverter found for request type [java.io.File] and content type [multipart/form-data]
无法写入请求:找不到适合请求类型 [java.io.File] 和内容类型 [multipart/form-data] 的 HttpMessageConverter
uploadUsingPUT1:上传使用PUT1:
Could not write request: no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data]
无法写入请求:找不到适合请求类型 [java.util.LinkedHashMap] 和内容类型 [multipart/form-data] 的 HttpMessageConverter
uploadUsingPUT2:上传使用PUT2:
Required request part 'file' is not present
所需的请求部分“文件”不存在
PLEASE SUGGEST请建议
这个问题现在似乎已经解决了,我在 2.0.x 版本的 feign-form 上,当我升级到 3.4.1 时它开始工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.