Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to handle the Multipartfile parameter of Feign remote call

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge points about how to deal with Feign remote call Multipartfile parameters. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

Feign remote call Multipartfile parameter

The problem encountered when writing business code today is that the front end requests A service to give the parameters to A service correctly, but when A service invokes B service, it throws the file parameters, which can not be received there, and will report an error in Multipartfile parameters.

The answer has been found on the Internet, and here is a record:

Solution

It has to be.

Create a new configuration class where your fegin service interface is exposed.

Package com.gobon.gbjk.file.api.config;import feign.form.spring.SpringFormEncoder;import org.springframework.beans.factory.ObjectFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.http.HttpMessageConverters;import org.springframework.cloud.openfeign.support.SpringEncoder;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;/** *

* feign configuration class *

* * @ projectName: gbjk-user * @ package: com.gobon.gbjk.file.api.config * @ className: FeignSupportConfig * @ author: wen jun tang * @ date: 12:25, December 21, 2021 * @ version: 1.0 * / @ Configurationpublic class FeignSupportConfig {@ Autowired private ObjectFactory messageConverters; @ Bean public SpringFormEncoder feignFormEncoder () {return new SpringFormEncoder (new SpringEncoder (messageConverters));}}

Then modify your interface file parameters with @ RequestPart:

@ PostMapping (value = "/ file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) AjaxResult upload (@ RequestPart ("file") MultipartFile file, @ RequestParam ("bucketName") String bucketName)

Call again, perfect solution!

The problem of passing parameters in Feign remote call

If it is a simple parameter, annotate with @ RequestParam or @ PathVariable

If it is an object parameter, annotate with @ RequestBody

These are all the contents of the article "how to handle the Multipartfile parameters of Feign remote calls". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report