How to modify the parameter name of MultipartFile in uploading?












0















I need to upload a MultipartFile to a third-party service via my own backend service. The parameter in the multipart form is 'nameA' but the third-party service need its param name is 'nameB'.



Normally I can solve it in two ways:




  1. Change the param name of frontend to 'nameB'

  2. Change the param name of MultipartFile to 'nameB' in backend service.


But I cannot change the frontend now, so I want to finger out how to modify the param name of MultipartFile in backend service.



The controller of backend service is:



@PostMapping("/url")
public Response method(@RequestParam("nameA") MultipartFile file) {
return Service.method(file);
}


In Feign Client for uploading file to third-party service:



@PostMapping(value = "/url1/url2", consumes = MULTIPART_FORM_DATA_VALUE)
Response method(@RequestParam("nameB") MultipartFile file);


However the use of specify the param with 👆 @RequestParam doesn't work.



So does anyone know how to modify the param name of MultipartFile? Thanks a lot!










share|improve this question























  • You can use RequestPart instead of RequestParam.

    – htpvl
    Oct 24 '18 at 1:52
















0















I need to upload a MultipartFile to a third-party service via my own backend service. The parameter in the multipart form is 'nameA' but the third-party service need its param name is 'nameB'.



Normally I can solve it in two ways:




  1. Change the param name of frontend to 'nameB'

  2. Change the param name of MultipartFile to 'nameB' in backend service.


But I cannot change the frontend now, so I want to finger out how to modify the param name of MultipartFile in backend service.



The controller of backend service is:



@PostMapping("/url")
public Response method(@RequestParam("nameA") MultipartFile file) {
return Service.method(file);
}


In Feign Client for uploading file to third-party service:



@PostMapping(value = "/url1/url2", consumes = MULTIPART_FORM_DATA_VALUE)
Response method(@RequestParam("nameB") MultipartFile file);


However the use of specify the param with 👆 @RequestParam doesn't work.



So does anyone know how to modify the param name of MultipartFile? Thanks a lot!










share|improve this question























  • You can use RequestPart instead of RequestParam.

    – htpvl
    Oct 24 '18 at 1:52














0












0








0








I need to upload a MultipartFile to a third-party service via my own backend service. The parameter in the multipart form is 'nameA' but the third-party service need its param name is 'nameB'.



Normally I can solve it in two ways:




  1. Change the param name of frontend to 'nameB'

  2. Change the param name of MultipartFile to 'nameB' in backend service.


But I cannot change the frontend now, so I want to finger out how to modify the param name of MultipartFile in backend service.



The controller of backend service is:



@PostMapping("/url")
public Response method(@RequestParam("nameA") MultipartFile file) {
return Service.method(file);
}


In Feign Client for uploading file to third-party service:



@PostMapping(value = "/url1/url2", consumes = MULTIPART_FORM_DATA_VALUE)
Response method(@RequestParam("nameB") MultipartFile file);


However the use of specify the param with 👆 @RequestParam doesn't work.



So does anyone know how to modify the param name of MultipartFile? Thanks a lot!










share|improve this question














I need to upload a MultipartFile to a third-party service via my own backend service. The parameter in the multipart form is 'nameA' but the third-party service need its param name is 'nameB'.



Normally I can solve it in two ways:




  1. Change the param name of frontend to 'nameB'

  2. Change the param name of MultipartFile to 'nameB' in backend service.


But I cannot change the frontend now, so I want to finger out how to modify the param name of MultipartFile in backend service.



The controller of backend service is:



@PostMapping("/url")
public Response method(@RequestParam("nameA") MultipartFile file) {
return Service.method(file);
}


In Feign Client for uploading file to third-party service:



@PostMapping(value = "/url1/url2", consumes = MULTIPART_FORM_DATA_VALUE)
Response method(@RequestParam("nameB") MultipartFile file);


However the use of specify the param with 👆 @RequestParam doesn't work.



So does anyone know how to modify the param name of MultipartFile? Thanks a lot!







java spring multipartform-data spring-cloud-feign






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 24 '18 at 1:49









SidSid

313




313













  • You can use RequestPart instead of RequestParam.

    – htpvl
    Oct 24 '18 at 1:52



















  • You can use RequestPart instead of RequestParam.

    – htpvl
    Oct 24 '18 at 1:52

















You can use RequestPart instead of RequestParam.

– htpvl
Oct 24 '18 at 1:52





You can use RequestPart instead of RequestParam.

– htpvl
Oct 24 '18 at 1:52












2 Answers
2






active

oldest

votes


















0














That is completely unrelated to your controllers spring annotations and instead depends on how you would upload that file to the 3rd party service. Since you mentioned uploading it, I assume you need to create a new HTTP multipart request in your backend service that would upload the file to the 3rd party service. When creating that request, you will be able to specify the name of the multipart part.






share|improve this answer
























  • Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

    – Sid
    Oct 24 '18 at 2:51











  • I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

    – Richard
    Oct 24 '18 at 3:06



















0














You can set a name of the MultipartFile in the FeignClient as you need, this is a sample from my project:



Сontroller API (receiving side):



@RestController
@RequestMapping("/files")
public class FilesController {

@PostMapping(path = "/upload")
@ResponseStatus(HttpStatus.CREATED)
public FileDescriptor upload(@RequestPart(value = "data") MultipartFile multipartFile) {
...
}
}


Feign client (sending side):



@FeignClient(value = "file-service", configuration = FeignConfig.class)
public interface ContentStorageFeign {

@ResponseBody
@PostMapping(value = "/files/upload", produces = MediaType.APPLICATION_JSON_VALUE)
FileDescriptor create(@RequestPart(value = "data") MultipartFile multipartFile);
}


And this is my FeignConfig:



@Configuration
public class FeignConfig {

@Bean
public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters) {
return new ResponseEntityDecoder(new SpringDecoder(messageConverters));
}

@Bean
public Encoder encoder(ObjectFactory<HttpMessageConverters> messageConverters) {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}


But if you need to create a new request(from a file received from somewhere) and rename this file before sending, this is another problem.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52960039%2fhow-to-modify-the-parameter-name-of-multipartfile-in-uploading%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    That is completely unrelated to your controllers spring annotations and instead depends on how you would upload that file to the 3rd party service. Since you mentioned uploading it, I assume you need to create a new HTTP multipart request in your backend service that would upload the file to the 3rd party service. When creating that request, you will be able to specify the name of the multipart part.






    share|improve this answer
























    • Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

      – Sid
      Oct 24 '18 at 2:51











    • I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

      – Richard
      Oct 24 '18 at 3:06
















    0














    That is completely unrelated to your controllers spring annotations and instead depends on how you would upload that file to the 3rd party service. Since you mentioned uploading it, I assume you need to create a new HTTP multipart request in your backend service that would upload the file to the 3rd party service. When creating that request, you will be able to specify the name of the multipart part.






    share|improve this answer
























    • Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

      – Sid
      Oct 24 '18 at 2:51











    • I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

      – Richard
      Oct 24 '18 at 3:06














    0












    0








    0







    That is completely unrelated to your controllers spring annotations and instead depends on how you would upload that file to the 3rd party service. Since you mentioned uploading it, I assume you need to create a new HTTP multipart request in your backend service that would upload the file to the 3rd party service. When creating that request, you will be able to specify the name of the multipart part.






    share|improve this answer













    That is completely unrelated to your controllers spring annotations and instead depends on how you would upload that file to the 3rd party service. Since you mentioned uploading it, I assume you need to create a new HTTP multipart request in your backend service that would upload the file to the 3rd party service. When creating that request, you will be able to specify the name of the multipart part.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 24 '18 at 2:23









    RichardRichard

    1,00165




    1,00165













    • Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

      – Sid
      Oct 24 '18 at 2:51











    • I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

      – Richard
      Oct 24 '18 at 3:06



















    • Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

      – Sid
      Oct 24 '18 at 2:51











    • I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

      – Richard
      Oct 24 '18 at 3:06

















    Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

    – Sid
    Oct 24 '18 at 2:51





    Hi, I understand that the spring annotation of @RequestParam is used to filter not to set now. Thank you, Is there any instruction for create http multipart request in feign client? I just pass the multipart file to feign client before.

    – Sid
    Oct 24 '18 at 2:51













    I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

    – Richard
    Oct 24 '18 at 3:06





    I must admit, that I don't know. I am only guessing here... If it is not working for you, ensure that you are using the latest version of the spring Feign thingy, cause they had some problems with their custom annotations on feign: github.com/spring-cloud/spring-cloud-netflix/issues/1201 If you are using the latest and greatest I'd try the plain feign approach mentioned here: stackoverflow.com/questions/31752779/…

    – Richard
    Oct 24 '18 at 3:06













    0














    You can set a name of the MultipartFile in the FeignClient as you need, this is a sample from my project:



    Сontroller API (receiving side):



    @RestController
    @RequestMapping("/files")
    public class FilesController {

    @PostMapping(path = "/upload")
    @ResponseStatus(HttpStatus.CREATED)
    public FileDescriptor upload(@RequestPart(value = "data") MultipartFile multipartFile) {
    ...
    }
    }


    Feign client (sending side):



    @FeignClient(value = "file-service", configuration = FeignConfig.class)
    public interface ContentStorageFeign {

    @ResponseBody
    @PostMapping(value = "/files/upload", produces = MediaType.APPLICATION_JSON_VALUE)
    FileDescriptor create(@RequestPart(value = "data") MultipartFile multipartFile);
    }


    And this is my FeignConfig:



    @Configuration
    public class FeignConfig {

    @Bean
    public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters) {
    return new ResponseEntityDecoder(new SpringDecoder(messageConverters));
    }

    @Bean
    public Encoder encoder(ObjectFactory<HttpMessageConverters> messageConverters) {
    return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
    }


    But if you need to create a new request(from a file received from somewhere) and rename this file before sending, this is another problem.






    share|improve this answer




























      0














      You can set a name of the MultipartFile in the FeignClient as you need, this is a sample from my project:



      Сontroller API (receiving side):



      @RestController
      @RequestMapping("/files")
      public class FilesController {

      @PostMapping(path = "/upload")
      @ResponseStatus(HttpStatus.CREATED)
      public FileDescriptor upload(@RequestPart(value = "data") MultipartFile multipartFile) {
      ...
      }
      }


      Feign client (sending side):



      @FeignClient(value = "file-service", configuration = FeignConfig.class)
      public interface ContentStorageFeign {

      @ResponseBody
      @PostMapping(value = "/files/upload", produces = MediaType.APPLICATION_JSON_VALUE)
      FileDescriptor create(@RequestPart(value = "data") MultipartFile multipartFile);
      }


      And this is my FeignConfig:



      @Configuration
      public class FeignConfig {

      @Bean
      public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters) {
      return new ResponseEntityDecoder(new SpringDecoder(messageConverters));
      }

      @Bean
      public Encoder encoder(ObjectFactory<HttpMessageConverters> messageConverters) {
      return new SpringFormEncoder(new SpringEncoder(messageConverters));
      }
      }


      But if you need to create a new request(from a file received from somewhere) and rename this file before sending, this is another problem.






      share|improve this answer


























        0












        0








        0







        You can set a name of the MultipartFile in the FeignClient as you need, this is a sample from my project:



        Сontroller API (receiving side):



        @RestController
        @RequestMapping("/files")
        public class FilesController {

        @PostMapping(path = "/upload")
        @ResponseStatus(HttpStatus.CREATED)
        public FileDescriptor upload(@RequestPart(value = "data") MultipartFile multipartFile) {
        ...
        }
        }


        Feign client (sending side):



        @FeignClient(value = "file-service", configuration = FeignConfig.class)
        public interface ContentStorageFeign {

        @ResponseBody
        @PostMapping(value = "/files/upload", produces = MediaType.APPLICATION_JSON_VALUE)
        FileDescriptor create(@RequestPart(value = "data") MultipartFile multipartFile);
        }


        And this is my FeignConfig:



        @Configuration
        public class FeignConfig {

        @Bean
        public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters) {
        return new ResponseEntityDecoder(new SpringDecoder(messageConverters));
        }

        @Bean
        public Encoder encoder(ObjectFactory<HttpMessageConverters> messageConverters) {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
        }


        But if you need to create a new request(from a file received from somewhere) and rename this file before sending, this is another problem.






        share|improve this answer













        You can set a name of the MultipartFile in the FeignClient as you need, this is a sample from my project:



        Сontroller API (receiving side):



        @RestController
        @RequestMapping("/files")
        public class FilesController {

        @PostMapping(path = "/upload")
        @ResponseStatus(HttpStatus.CREATED)
        public FileDescriptor upload(@RequestPart(value = "data") MultipartFile multipartFile) {
        ...
        }
        }


        Feign client (sending side):



        @FeignClient(value = "file-service", configuration = FeignConfig.class)
        public interface ContentStorageFeign {

        @ResponseBody
        @PostMapping(value = "/files/upload", produces = MediaType.APPLICATION_JSON_VALUE)
        FileDescriptor create(@RequestPart(value = "data") MultipartFile multipartFile);
        }


        And this is my FeignConfig:



        @Configuration
        public class FeignConfig {

        @Bean
        public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters) {
        return new ResponseEntityDecoder(new SpringDecoder(messageConverters));
        }

        @Bean
        public Encoder encoder(ObjectFactory<HttpMessageConverters> messageConverters) {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
        }


        But if you need to create a new request(from a file received from somewhere) and rename this file before sending, this is another problem.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 3:26









        Anatoliy KorovinAnatoliy Korovin

        1065




        1065






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52960039%2fhow-to-modify-the-parameter-name-of-multipartfile-in-uploading%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Futebolista

            Jornalista