// 将生成的 excel 上传到 oss 服务上
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
redStarExportExcel.write(outputStream);
ThreadLocalRandom random = ThreadLocalRandom.current();
File tempDir = Files.createTempDir();
String filePath = tempDir.getPath() + "/" + random.nextInt(100000) + exportExcel.getFileName();
OutputStream fileOutputStream = new FileOutputStream(filePath);
fileOutputStream.write(outputStream.toByteArray());
FileSystemResource resource = new FileSystemResource(new File(filePath));
outputStream.close();
fileOutputStream.close();
FileUtils.deleteQuietly(tempDir);
return AsyncUploadUtil.insideUpload(resource);
@Autowired
private RestTemplate fileRestTemplate;
public static String insideUpload(FileSystemResource resource){
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> bodyParams = new LinkedMultiValueMap<>();
bodyParams.add("file", resource);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(bodyParams, headers);
ResponseEntity<Result> responseEntity = asyncUploadUtil.fileRestTemplate.postForEntity(fileUploadUrl, requestEntity, Result.class);
return responseEntity.getBody().getData();
}