try {
// minio中的地址
String fileUrl = "adc49bf6c0ea50ae172560ef7a5d7bce:aaa.xls";
Response download = remoteFileService.fileDownload(fileUrl.split(":")[0]);
// 获取文件的 inputStream流
InputStream is = download.body().asInputStream();
// 设置下载格式
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
String contentDisposition = "attachment;fileName=" + java.net.URLEncoder.encode("filename", "UTF-8");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", contentDisposition);
response.setCharacterEncoding("UTF-8");
// QdpmsFileServiceImpl.writeFile(TemplateExcelUtils.getOutputStream("testName", response), is);
// 下载的地址
String destPath = "C:/Users/yourUserName/Desktop/aaa.xls";
// 设置文件输出流
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(destPath);
byte[] buffer = new byte[1024];
int bytesRead;
// 将数据写入到要输出的文件中
while ((bytesRead = is.read(buffer)) != -1) {
outStream.write(buffer, 0, bytesRead);
}
} finally {
if (outStream != null) {
outStream.close();
}
if (is != null) {
is.close();
}
}
} catch (Exception e) {
log.info(e.getMessage());
throw new RuntimeException(e.getMessage());
}
return null;
从MINIO获取数据并下载到本地
最新推荐文章于 2025-04-16 15:02:24 发布