private JSONObject upload(File file) {
// url
String uploadUrl = "https://yinji.gaoshan.co/api/gs-enterprise-admin/gs/file/upload";
// 请求头参数
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setConnection("Keep-Alive");
headers.setCacheControl("no-cache");
headers.add("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiIxNTY1NTE4OTE5OCIsInNjb3BlIjpbImFsbCJdLCJpZCI6OCwiZXhwIjoxNjM5MTg5MTg1LCJhdXRob3JpdGllcyI6WyI2X-aZrumAmueUqOaItyJdLCJqdGkiOiIxOGRkMWY1MS02MzhhLTRlOGYtYjdlOS1hOGM1OGNmNDk2NzQiLCJjbGllbnRfaWQiOiJlbnRlcnByaXNlLWFkbWluLWFwcCJ9.aOC_mUnjPwbvD_7jY7TuiA4_WM0Kcuiuqc49yPP-kSfXr-x_P5UrBbjw7id8I849sNwoJB6tIyF6Hpwow_MOIlVX0ErECAlcNPOEJQ2eefrUcmEf-wQ9l5MV_k_j1l7ndC0j4m7GBwfrSde3CcZbWU6myd4CVG3_OF5nmUKRtcQ");
// 封装请求 body
FileSystemResource resource = new FileSystemResource(file);
MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
form.add("file", resource);
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(form, headers);
// 发起请求
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(uploadUrl, httpEntity, JSONObject.class);
final JSONObject jsonObject = responseEntity.getBody();
log.info("jsonObject : {} ", jsonObject);
return jsonObject;
}