|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.supervision.manage.service.impl;
|
|
|
|
package com.supervision.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@ -18,6 +19,8 @@ import java.io.BufferedInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
@ -78,11 +81,12 @@ public class FileManageServiceImpl implements FileManageService {
|
|
|
|
|
|
|
|
|
|
|
|
try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId());
|
|
|
|
try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId());
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream()){
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream()){
|
|
|
|
if (StrUtil.isNotEmpty(fileResource.getFileType())){
|
|
|
|
String contentType = StrUtil.isEmpty(fileResource.getFileType()) ? "application/octet-stream" : fileResource.getFileType();
|
|
|
|
response.setContentType(fileResource.getFileType());
|
|
|
|
response.setContentType(contentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Objects.nonNull(fileResource.getFileName())){
|
|
|
|
if (Objects.nonNull(fileResource.getFileName())){
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileResource.getFileName());
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" +
|
|
|
|
|
|
|
|
URLEncoder.encode(fileResource.getFileName(), "UTF-8"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte[] bytes = new byte[1024];
|
|
|
|
byte[] bytes = new byte[1024];
|
|
|
@ -101,7 +105,16 @@ public class FileManageServiceImpl implements FileManageService {
|
|
|
|
|
|
|
|
|
|
|
|
FileResource fileResource = fileResourceService.getById(fileId);
|
|
|
|
FileResource fileResource = fileResourceService.getById(fileId);
|
|
|
|
Assert.notNull(fileResource,"文件不存在");
|
|
|
|
Assert.notNull(fileResource,"文件不存在");
|
|
|
|
File tempFile = FileUtil.createTempFile();
|
|
|
|
String prefix = null;
|
|
|
|
|
|
|
|
String suffix = null;
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(fileResource.getFileName())){
|
|
|
|
|
|
|
|
List<String> split = StrUtil.split(fileResource.getFileName(), ".");
|
|
|
|
|
|
|
|
prefix = CollUtil.getFirst(split);
|
|
|
|
|
|
|
|
if (CollUtil.size(split) > 1){
|
|
|
|
|
|
|
|
suffix = "." + split.get(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
File tempFile = StrUtil.isEmpty(prefix) ? FileUtil.createTempFile() : FileUtil.createTempFile(prefix,suffix,true);
|
|
|
|
try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId());
|
|
|
|
try (InputStream inputStream = MinioUtil.download(fileResource.getMinioId());
|
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
|
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
|
|
|
|
byte[] bytes = new byte[1024];
|
|
|
|
byte[] bytes = new byte[1024];
|
|
|
|