简体   繁体   English

找不到适合请求类型 [java.util.LinkedHashMap] 和内容类型 [multipart/form-data] 的 HttpMessageConverter

[英]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.

相关问题 RestTemplate无法编写请求:找不到适合请求类型[java.util.HashMap]的HttpMessageConverter - RestTemplate Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap] 无法写入请求:找不到适合请求类型和内容类型的HttpMessageConverter [application / x-java-serialized-object] - Could not write request: no suitable HttpMessageConverter found for request type and content type [application/x-java-serialized-object] 找不到适合响应类型和内容类型的HttpMessageConverter - no suitable HttpMessageConverter found for response type and content type 找不到能够从类型 [java.util.LinkedHashMap 进行转换的转换器<?, ?> ] 输入 - No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type Java Android Spring:找不到适合请求类型的HttpMessageConverter - java android spring: no suitable HttpMessageConverter found for request type 如何使用java.util.LinkedHashMap $ EntryIterator类型访问对象值 - How to access the object value with java.util.LinkedHashMap$EntryIterator type 使用 header Content-Type:multipart/form-data 发送 java POST 请求? - Send the java POST request with header Content-Type:multipart/form-data? 找不到能够从类型 [java.util.LinkedHashMap 进行转换的转换器<?, ?> ] 输入 [java.lang.String] - Spring 配置服务器 - No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String] - Spring config server 请求不包含多部分/表单数据或多部分/混合流,内容类型标头为false - the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is false 没有找到适合响应类型的 HttpMessageConverter - no suitable HttpMessageConverter found for response type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM