Version info
spring-cloud-openfeign-core:2.1.5.RELEASE
spring-cloud-starter-openfeign:2.1.0.RELEASE
feign-form:3.8.0
feign-form-spring:3.8.0
feign-core:10.4.0
Description I have 2 server A and B, a file such as 'file1' is uploaded to A by MultipartFile , then i will process the file but no reconstruct the object and send it to B server by fein client and use the different part name such as 'file2'.
And then i try specify the part name in annotation, like this @RequestPart("file2"), but it doesn't work.
After i read the code of spring-feign-form-encoder, i find that it use the return value of method MultipartFile.getName() as part name, but MultipartFile can not modify this field.
Sample Server A:
@PostMapping(value="/uploadattachbatch", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void uploadAttachRecBatchHandler(
HttpServletRequest request,
HttpServletResponse response,
@RequestPart(value = "attachrec") MultipartFile[] attachrec,
@RequestParam(required = true) Long recID,
@RequestParam(required = false) Long actID,
@RequestParam(required = false) Integer actDefID,
@RequestParam(required = false) Integer mediaUnionFlag,
@RequestParam(required = true) String attachDesc) {
// send it to B by feignClient
mediaStreamApiManager.uploadMediaHandler(JsonUtils.toJsonString(media), humanID,
0, null, null, null, null, null, files, Boolean.FALSE, Boolean.FALSE);
}
FeignClient Api:
@PostMapping(value = "/media/uploadinfo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
ResultInfo uploadMediaHandler(@RequestParam(value = "mediaInfo") String mediaInfo,
@RequestParam(value = "humanID") Integer humanID,
@RequestParam(value = "fromMobile") Integer fromMobile,
@RequestParam(value = "mediaSize") Long mediaSize,
@RequestParam(value = "partSize") Long partSize,
@RequestParam(value = "blockSize") Long blockSize,
@RequestParam(value = "partNO") Integer partNO,
@RequestParam(value = "fn") String fn,
@RequestPart(value = "files")MultipartFile[] files,
@RequestParam(value = "replace")Boolean replace,
@RequestParam(value = "checkExist")Boolean checkExist);
config:
class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder () {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
Service B:
@RequestMapping(value = "/media/uploadinfo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResultInfo uploadMediaInfoHandler(@RequestParam(value = "mediaInfo") String mediaInfo,
@RequestParam(required = false) Integer humanID,
@RequestParam(required = false) Integer fromMobile,
@RequestParam(required = false) Long mediaSize,
@RequestParam(required = false) Long partSize,
@RequestParam(required = false) Long blockSize,
@RequestParam(required = false) Integer partNO,
@RequestParam(required = false) String fn,
@RequestPart(value = "files") MultipartFile[] files,
@RequestParam(required = false, defaultValue = "false") Boolean replace,"false")
@RequestParam(required = false, defaultValue = "false") Boolean checkExist){
// you will find that files is null, because the part name is not files but attachrec
}
Comment From: spencergibb
Please open an issue in https://github.com/OpenFeign/feign-form
Comment From: GongchuangSu
It responds too slowly!Why can't you solve this problem