0
votes

I have to make a call to upload a file to below service:-

@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public Response uploadFile(
       @RequestParam(value="file", required=true) MultipartFile file, 
       @RequestParam(value="asOfDate" Date asOfDate,
       @RequestHeader(value = "metric") String metric,
       @RequestHeader(value = "user_id") String userId,
       @RequestHeader(value = "user_name") String userName,
       @RequestHeader(value = "user_company_id") String userCompanyId){
 }

As of now I am using RestTemplate to make a call to this service, but now I need to convert the RestTemplate calls to Feign Client.

I'm trying to accomplish a multipart file upload using feign, but I can't seem to find a good example of it anywhere.

1
Is it working without the feign client ? Make sure it is working for a regular HTTP Post possibly by adding a unit test to it. - royalghost
Check SO or example - Amit K Bist
@PrabinPaudel Yes it is working without feign client. I want to convert these calls to feign. - Sharda Prasad Jaiswal
@AmitKBist these examples are not working, I am getting "Method has too many body parameters error". - Sharda Prasad Jaiswal

1 Answers

0
votes

Following code should work

@FeignClient(
        url = "HOST_URL",
        name = "FileUploadClient")
public interface FileUploadClient {

@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public Response uploadFile(
       @PathVariable(value="file", required=true) MultipartFile file, 
       @RequestParam(value="asOfDate" Date asOfDate,
       @RequestHeader(value = "metric") String metric,
       @RequestHeader(value = "user_id") String userId,
       @RequestHeader(value = "user_name") String userName,
       @RequestHeader(value = "user_company_id") String userCompanyId){
 }
}