云前置文件文件目录功能
This commit is contained in:
@@ -81,6 +81,29 @@ public interface BusinessTopic {
|
||||
|
||||
String RMP_EVENT_DETAIL_TOPIC = "rmpEventDetailTopic";
|
||||
|
||||
// /**
|
||||
// * 云前置文件信息请求主题
|
||||
// */
|
||||
// String FILE_INFO_REQUEST_TOPIC = "fileInfoRequestTopic";
|
||||
//
|
||||
// /**
|
||||
// * 云前置文件信息响应主题
|
||||
// */
|
||||
// String FILE_INFO_RESPONSE_TOPIC = "fileInfoResponseTopic";
|
||||
//
|
||||
// /**
|
||||
// * 云前置文件下载请求主题
|
||||
// */
|
||||
// String FILE_DOWNLOAD_REQUEST_TOPIC = "fileDownloadRequestTopic";
|
||||
// /**
|
||||
// * 云前置文件下载响应主题
|
||||
// */
|
||||
// String FILE_DOWNLOAD_RESPONSE_TOPIC = "fileDownloadResponseTopic";
|
||||
|
||||
String CLOUD_TOPIC = "Cloud_Topic";
|
||||
|
||||
String CLOUD_REPLY_TOPIC = "Cloud_Reply_Topic";
|
||||
|
||||
|
||||
interface AppDataTag {
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ package com.njcn.oss.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.njcn.ali.oss.config.AliYunOssConfig;
|
||||
import com.njcn.ali.oss.util.AliYunOssUtils;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.huawei.obs.config.HuaweiObsProperties;
|
||||
import com.njcn.huawei.obs.util.OBSUtil;
|
||||
import com.njcn.minioss.bo.MinIoUploadResDTO;
|
||||
import com.njcn.minioss.config.MinIossProperties;
|
||||
@@ -12,6 +15,8 @@ import com.njcn.minioss.util.MinIoUtils;
|
||||
import com.njcn.oss.constant.GeneralConstant;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.enums.OssResponseEnum;
|
||||
import com.obs.services.ObsClient;
|
||||
import com.obs.services.model.PutObjectRequest;
|
||||
import io.minio.*;
|
||||
import io.minio.messages.Item;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -70,6 +75,11 @@ public class FileStorageUtil {
|
||||
*/
|
||||
private final AliYunOssUtils aliYunOssUtils;
|
||||
|
||||
private final HuaweiObsProperties huaweiObsProperties;
|
||||
|
||||
private final OSS ossClient;
|
||||
private final AliYunOssConfig ossConfig;
|
||||
|
||||
|
||||
/***
|
||||
* 上传MultipartFile文件,
|
||||
@@ -442,4 +452,62 @@ public class FileStorageUtil {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void mkdir(String directoryPath) {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
this.createDirectoryHW(directoryPath);
|
||||
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||
minIoUtils.createDirectory(minIossProperties.getBucket(), directoryPath);
|
||||
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.AliYUN_OSS) {
|
||||
this.createDirectoryAli(directoryPath);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 华为文件服务器创建空目录
|
||||
*
|
||||
* @param dirPath
|
||||
*/
|
||||
private void createDirectoryHW(String dirPath) {
|
||||
ObsClient obsClient = null;
|
||||
try {
|
||||
obsClient = this.huaweiObsProperties.getInstance();
|
||||
String bucketName = this.huaweiObsProperties.getObs().getBucket();
|
||||
|
||||
// 确保路径以 / 结尾
|
||||
String directoryKey = dirPath.endsWith("/") ? dirPath : dirPath + "/";
|
||||
|
||||
// 创建空对象作为目录占位符
|
||||
InputStream emptyStream = new ByteArrayInputStream(new byte[0]);
|
||||
PutObjectRequest request = new PutObjectRequest(bucketName, directoryKey, emptyStream);
|
||||
obsClient.putObject(request);
|
||||
|
||||
log.info("已创建目录占位符:" + directoryKey);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("创建目录失败" + dirPath, e);
|
||||
} finally {
|
||||
this.huaweiObsProperties.destroy(obsClient);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阿里云文件服务器创建空目录
|
||||
*
|
||||
* @param dirPath
|
||||
*/
|
||||
public void createDirectoryAli(String dirPath) {
|
||||
try {
|
||||
// 确保路径以 / 结尾,表示目录
|
||||
String directoryKey = dirPath.endsWith("/") ? dirPath : dirPath + "/";
|
||||
|
||||
// 创建空输入流作为目录占位符
|
||||
ByteArrayInputStream emptyStream = new ByteArrayInputStream(new byte[0]);
|
||||
|
||||
this.ossClient.putObject(this.ossConfig.getBucket(), directoryKey, emptyStream);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("创建目录失败:" + dirPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,4 +115,8 @@ public interface AppRedisKey {
|
||||
* 补召文件
|
||||
*/
|
||||
String MAKE_UP_FILES = "makeUpFilesKey:";
|
||||
|
||||
String COMMON_REQUEST = "commonRequestKey:";
|
||||
|
||||
String COMMON_RESOPNSE = "commonResponseKey:";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user