@SpringBootApplication
public class FeignUploadFirstApplication {
@RestController
public class UploadController {
@RequestMapping(value = "/uploadFile",method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String handleFileUpload(@RequestPart(value = "file") MultipartFile file) {
return file.getOriginalFilename();
}
}
public static void main(String[] args) {
SpringApplication.run(FeignUploadFirstApplication.class, args);
}
}
1.feign相關的依賴
目前創(chuàng)新互聯建站已為上1000家的企業(yè)提供了網站建設、域名、雅安服務器托管、網站托管運營、企業(yè)網站設計、遵義網站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>3.0.3</version>
</dependency>
2.feign配置類
@Configuration
public class FeignMultipartSupportConfig {
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder();
}
}
3.feign調用接口 注解中加入配置類
@FeignClient(value = "xxx", configuration = FeignMultipartSupportConfig.class)
public interface IUploadService {
/**
* 文件上傳
* @param file 文件
* @return
*/
@RequestMapping(value = "upload/uppic", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResultModel<String> uppic(@RequestPart(value = "file")MultipartFile file, @RequestParam Map<String,Object> map);
}
4.上傳接口
@RestController
public class UploadController {
@Autowired
IUploadService uploadService;
@RequestMapping(value = "/uploadFile",method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String handleFileUpload(@RequestPart(value = "file") MultipartFile file) {
return uploadService.uppic(file);
}
}
FileInputStream fileInputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), ContentType.TEXT_PLAIN.toString(), fileInputStream);
新聞標題:SpringbootFeign文件上傳
本文鏈接:http://jinyejixie.com/article30/iicgso.html
成都網站建設公司_創(chuàng)新互聯,為您提供網站維護、電子商務、定制網站、網站制作、小程序開發(fā)、服務器托管
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯