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.
}

最新文章

  1. Java学习笔记之方法重载
  2. 利用stack结构,将中缀表达式转换为后缀表达式并求值的算法实现
  3. java 的 sqlHelper,改改之后也适用于不使用 EF 的 C# 项目,包含查询和建表。
  4. 用直接路径(direct-path)insert提升性能的两种方法
  5. 5.19[bzoj树网的核]
  6. @Scheduled 注解
  7. Windows Server 2008 R2怎样设置自动登陆
  8. NSIS学习记录の----NSIS多语言安装以及详解
  9. 磁盘参数修订[转自vbird]
  10. php面向对象的三大特征 封装,继承,多态
  11. XML文件的生成与读取
  12. python中字典dict pop方法
  13. Fast Intro To Java Programming (1)
  14. C/C++ 知识点---sizeof使用规则及陷阱分析(网摘)
  15. 从Thread.start()方法看Thread源码,多次start一个线程会怎么样
  16. bzoj 2440 (莫比乌斯函数)
  17. 酷炫的loading
  18. Django 视图系统
  19. Assembly Required【思维】
  20. 《Android进阶之光》--事件总线

热门文章

  1. IDEA设置项目文件自动Add到Svn/Git
  2. 迷你商城后台管理系统————stage3项目部署测试汇总
  3. XSL-FO知识点【一】
  4. ISCC之msc4
  5. event.target事件
  6. Git收藏
  7. javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/pay/index] again. Check your ViewResolver setup!
  8. 《Exception》第五次作业:项目需求分析改进与系统设计
  9. 查看mysql日志文件
  10. C++语言第一课的学习