i试图集成文件上传服务,该服务已注册为Eureka Discovery Infrastructure。
我的服务,说/myfile/上传的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"
我已经为此服务创建了一个客户端接口,以下是我创建的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);
}
要提供编码器,我在下面添加了编码器:
@Bean
public Encoder feignEncoder() {
ObjectFactory<HttpMessageConverters> objectFactory = () ->
new HttpMessageConverters(new FormHttpMessageConverter());
// return new SpringEncoder(objectFactory);
return new FormEncoder(new SpringEncoder(objectFactory));
}
我仍然有所有三种方法的例外:
上载:
无法编写请求:找不到适合的httpmessageconverter 请求类型[Java.io.file]和内容类型[Multipart/form-data]
uploadusting1:
无法编写请求:找不到适合的httpmessageconverter 请求类型[java.util.linkedhashmap]和内容类型 [Multipart/form-data]
uploadusting2:
所需请求零件"文件"不存在
请建议
现在似乎已经解决了这个问题,当我升级到3.4.1时,我正在使用2.0.x版本的版本。