|
@@ -17,11 +17,14 @@ import io.minio.messages.Item;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.Headers;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -120,9 +123,6 @@ public class MinioStorageServiceImpl implements IFileStorageService, Initializin
|
|
|
return;
|
|
|
}
|
|
|
// 开始检查分片,每次都从头到尾检查一遍.防止出现并发上传的分片
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
String lastObjName = objectNames.get(objectNames.size() - 1);
|
|
|
StatObjectResponse objectResponse = minioClient
|
|
|
.statObject(StatObjectArgs.builder().bucket(bucketName).object(lastObjName).build());
|
|
@@ -134,13 +134,20 @@ public class MinioStorageServiceImpl implements IFileStorageService, Initializin
|
|
|
}
|
|
|
InputStream lastObj = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(lastObjName).build());
|
|
|
byte[] lastBytes = IoUtil.readBytes(lastObj);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public InputStream download(String bucketName, String fileName) {
|
|
|
+ return download(bucketName,fileName,null,null);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 文件下载
|
|
|
+ * @param bucketName 桶名
|
|
|
+ * @param fileName 文件名
|
|
|
+ * @param response 响应对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public InputStream download(String bucketName, String fileName, HttpServletResponse response,String realFileName) {
|
|
|
// 容错判断
|
|
|
if(StrUtil.isBlank(fileName)) {
|
|
|
throw new BusinessException("下载文件参数有误!");
|
|
@@ -149,9 +156,18 @@ public class MinioStorageServiceImpl implements IFileStorageService, Initializin
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 下载文件
|
|
|
-// return minioClient.getObject(bucketName, fileName);
|
|
|
- return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName)
|
|
|
- .build());
|
|
|
+ GetObjectResponse objectResponse = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName).build());
|
|
|
+ if (null!=response){
|
|
|
+ // 添加header
|
|
|
+ Headers headers = objectResponse.headers();
|
|
|
+ headers.names().forEach(name->response.addHeader(name,headers.get(name)));
|
|
|
+ if (StrUtil.isNotBlank(realFileName)){
|
|
|
+ response.addHeader(FileCommonConst.REPONSE_HEAD_CONTENT_DISPOSITION, StrUtil
|
|
|
+ .format(FileCommonConst.REPONSE_HEAD_CONTENT_DISPOSITION_ATTACHMENT,
|
|
|
+ URLEncoder.encode(realFileName, "UTF-8")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objectResponse;
|
|
|
} catch (Exception e) {
|
|
|
FileExceptionHandler.handleException(e);
|
|
|
}
|