diff --git a/continew-starter-storage/continew-starter-storage-core/src/main/java/top/continew/starter/storage/util/StorageUtils.java b/continew-starter-storage/continew-starter-storage-core/src/main/java/top/continew/starter/storage/util/StorageUtils.java
index 4cfca27a..1c1c1a15 100644
--- a/continew-starter-storage/continew-starter-storage-core/src/main/java/top/continew/starter/storage/util/StorageUtils.java
+++ b/continew-starter-storage/continew-starter-storage-core/src/main/java/top/continew/starter/storage/util/StorageUtils.java
@@ -71,16 +71,29 @@ public class StorageUtils {
}
/**
- * 默认路径地址 格式 2024/03/10/
+ * 本地存储默认路径地址 格式
+ *
mac/linux : 2024/03/10/>
+ *
windows : 2024\03\10\>
*
* @return {@link String }
*/
- public static String defaultPath() {
+ public static String localDefaultPath() {
LocalDate today = LocalDate.now();
return Paths.get(String.valueOf(today.getYear()), String.valueOf(today.getMonthValue()), String.valueOf(today
.getDayOfMonth())) + StringConstants.SLASH;
}
+ /**
+ * 对象存储默认路径 格式 2024/03/10/
+ *
+ * @return {@link String }
+ */
+ public static String ossDefaultPath() {
+ LocalDate today = LocalDate.now();
+ return today.getYear() + StringConstants.SLASH + today.getMonthValue() + StringConstants.SLASH + today
+ .getDayOfMonth() + StringConstants.SLASH;
+ }
+
/**
* 根据 endpoint 判断是否带有 http 或 https,如果没有则加上 http 前缀。
*
diff --git a/continew-starter-storage/continew-starter-storage-local/src/main/java/top/continew/starter/storage/strategy/LocalStorageStrategy.java b/continew-starter-storage/continew-starter-storage-local/src/main/java/top/continew/starter/storage/strategy/LocalStorageStrategy.java
index 39bc36d5..f022d43c 100644
--- a/continew-starter-storage/continew-starter-storage-local/src/main/java/top/continew/starter/storage/strategy/LocalStorageStrategy.java
+++ b/continew-starter-storage/continew-starter-storage-local/src/main/java/top/continew/starter/storage/strategy/LocalStorageStrategy.java
@@ -125,7 +125,7 @@ public class LocalStorageStrategy implements StorageStrategy {
String formatFileName = StorageUtils.formatFileName(fileName);
// 判断文件路径是否为空 为空给默认路径 格式 2024/12/30/
if (StrUtil.isEmpty(path)) {
- path = StorageUtils.defaultPath();
+ path = StorageUtils.localDefaultPath();
}
// 判断文件夹是否存在 不存在则创建
Path folderPath = Paths.get(bucketName, path);
diff --git a/continew-starter-storage/continew-starter-storage-oss/src/main/java/top/continew/starter/storage/strategy/OssStorageStrategy.java b/continew-starter-storage/continew-starter-storage-oss/src/main/java/top/continew/starter/storage/strategy/OssStorageStrategy.java
index f6eb6f40..7db388d1 100644
--- a/continew-starter-storage/continew-starter-storage-oss/src/main/java/top/continew/starter/storage/strategy/OssStorageStrategy.java
+++ b/continew-starter-storage/continew-starter-storage-oss/src/main/java/top/continew/starter/storage/strategy/OssStorageStrategy.java
@@ -54,7 +54,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
-import java.nio.file.Paths;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Base64;
@@ -157,7 +156,7 @@ public class OssStorageStrategy implements StorageStrategy {
String formatFileName = StorageUtils.formatFileName(fileName);
// 判断文件路径是否为空 为空给默认路径 格式 2024/12/30/
if (StrUtil.isEmpty(path)) {
- path = StorageUtils.defaultPath();
+ path = StorageUtils.ossDefaultPath();
}
ThumbnailResp thumbnailResp = null;
//判断是否需要上传缩略图 前置条件 文件必须为图片
@@ -174,7 +173,7 @@ public class OssStorageStrategy implements StorageStrategy {
}
String eTag = etag;
// 构建 上传后的文件路径地址 格式 xxx/xxx/xxx.jpg
- String filePath = Paths.get(path, formatFileName).toString();
+ String filePath = path + formatFileName;
// 构建 文件上传记录 并返回
return buildStorageRecord(bucketName, fileName, filePath, eTag, fileBytes.length, thumbnailResp);
} catch (IOException e) {
@@ -185,7 +184,7 @@ public class OssStorageStrategy implements StorageStrategy {
@Override
public void upload(String bucketName, String fileName, String path, InputStream inputStream, String fileType) {
// 构建 S3 存储 文件路径
- String filePath = Paths.get(path, fileName).toString();
+ String filePath = path + fileName;
try {
long available = inputStream.available();
// 构建异步请求体,指定内容长度
@@ -203,7 +202,8 @@ public class OssStorageStrategy implements StorageStrategy {
// 写入输入流内容到请求体
requestBody.writeInputStream(inputStream);
CompletedUpload uploadResult = upload.completionFuture().join();
- etag = uploadResult.response().eTag();
+
+ etag = uploadResult.response().eTag().replace("\"", "");
} catch (IOException e) {
throw new BusinessException("文件上传异常", e);
}
@@ -225,7 +225,7 @@ public class OssStorageStrategy implements StorageStrategy {
inputStream = new ByteArrayInputStream(outputStream.toByteArray());
// 上传文件
this.upload(bucketName, thumbnailFileName, path, inputStream, fileType);
- return new ThumbnailResp((long)outputStream.size(), Paths.get(path, thumbnailFileName).toString());
+ return new ThumbnailResp((long)outputStream.size(), path + thumbnailFileName);
} catch (IOException e) {
throw new BusinessException("缩略图处理异常", e);
}
@@ -326,7 +326,7 @@ public class OssStorageStrategy implements StorageStrategy {
uploadResp.setThumbnailUrl(thumbnailUrl);
uploadResp.setThumbnailSize(thumbnailSize);
uploadResp.seteTag(eTag);
- uploadResp.setPath(Paths.get(bucketName, filePath).toString());
+ uploadResp.setPath(bucketName + filePath);
uploadResp.setBucketName(bucketName);
uploadResp.setCreateTime(LocalDateTime.now());
storageDao.add(uploadResp);