Spring’s RestTemplate
2024-08-26 17:55:12
Spring’s RestTemplate
/**
* After the word document is generated in memory we can upload it to the server.
*
* @param fileContents The byte array we're wanting to POST
* @param filename The name of the file you're uploading. You can make yours up if you want.
*/
private static void uploadWordDocument(byte[] fileContents, final String filename) {
RestTemplate restTemplate = new RestTemplate();
String fooResourceUrl = "http://localhost:8080/spring-rest/foos"; // Dummy URL.
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>(); map.add("name", filename);
map.add("filename", filename); // Here we
ByteArrayResource contentsAsResource = new ByteArrayResource(fileContents) {
@Override
public String getFilename() {
return filename; // Filename has to be returned in order to be able to post.
}
}; map.add("file", contentsAsResource); // Now you can send your file along.
String result = restTemplate.postForObject(fooResourceUrl, map, String.class); // Proceed as normal with your results.
}
最新文章
- Java学习笔记之方法重载
- 利用stack结构,将中缀表达式转换为后缀表达式并求值的算法实现
- java 的 sqlHelper,改改之后也适用于不使用 EF 的 C# 项目,包含查询和建表。
- 用直接路径(direct-path)insert提升性能的两种方法
- 5.19[bzoj树网的核]
- @Scheduled 注解
- Windows Server 2008 R2怎样设置自动登陆
- NSIS学习记录の----NSIS多语言安装以及详解
- 磁盘参数修订[转自vbird]
- php面向对象的三大特征 封装,继承,多态
- XML文件的生成与读取
- python中字典dict pop方法
- Fast Intro To Java Programming (1)
- C/C++ 知识点---sizeof使用规则及陷阱分析(网摘)
- 从Thread.start()方法看Thread源码,多次start一个线程会怎么样
- bzoj 2440 (莫比乌斯函数)
- 酷炫的loading
- Django 视图系统
- Assembly Required【思维】
- 《Android进阶之光》--事件总线
热门文章
- IDEA设置项目文件自动Add到Svn/Git
- 迷你商城后台管理系统————stage3项目部署测试汇总
- XSL-FO知识点【一】
- ISCC之msc4
- event.target事件
- Git收藏
- javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/pay/index] again. Check your ViewResolver setup!
- 《Exception》第五次作业:项目需求分析改进与系统设计
- 查看mysql日志文件
- C++语言第一课的学习