使用RestTemplate上传文件
最近在用Spring Cloud,搭建微服务应用,其中一个微服务是把文件上传到七牛,其他的文件上传都是通过他。但是在使用Fegin调用该服务的接口的时候,一直有问题,恩--------先用RestTemplate试试
博客小福利 点我 阿里云优惠券免费取
步骤
1、声明对象
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
2、发送请求
@Autowired
private RestTemplate rest;
public void ExceptInfoForRestTemplate(String excelTitle, List<String[]> arrayList) throws
ParseException {
String fileLocal="E://xxccccccccc"
String url = "https://xxxxxx.com/upload";
FileSystemResource resource = new FileSystemResource(new File(fileLocal));
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("file", resource);
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param);
ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
System.out.println(responseEntity.getBody());
}
我的官网https://guan2ye.com
我的CSDN地址https://blog.csdn.net/chenjianandiyi
我的简书地址https://www.jianshu.com/u/9b5d1921ce34
我的githubhttps://github.com/javanan
我的码云地址https://gitee.com/jamen/
最后更新:2017-11-03 13:03:35
上一篇:
docker清理日志
下一篇:
新买的6splus被锁定怎么办
Java并发——线程间协作(wait、notify、sleep、yield、join)
tomcat中jsp引用图片img的src属性带中文路径无法显示的解决
Javax.swing中JFrame.getContentPane().add(pane)与JFrame.add(pane)有何区别?
Clojure-Control 0.3.0 is out
Python虚拟机的初始化概览
重磅!支付宝小程序悄然上线,分享能力更强大!ofo小程序怒怼摩拜小程序
WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[下篇]
android超炫的动画效果
jQuery提交表单
Uber数据基础架构现在及未来