package com.example.hystrix.controller; import org.springframework.core.io.FileSystemResource; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.io.File; public class Demo{ public void uploadTest() { String url = "http://localhost:8080/upload"; //上传的地址 String filePath = "D:/test/test.mp4"; RestTemplate rest = new RestTemplate(); FileSystemResource resource = new FileSystemResource(new File(filePath)); MultiValueMap<String, Object> param = new LinkedMultiValueMap<>(); param.add("file", resource); //MultipartFile的名称 String restResult = rest.postForObject(url, param, String.class); System.out.println(restResult); } }
原文:https://www.cnblogs.com/Alwaysbecoding/p/12877950.html