From 214af79101bc6889d16be05b139b27d00e1b3c8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A0=81=E5=8C=A0=E5=90=9B?=
示例微服务应用 |
示例单体应用 |
diff --git a/oss-minio/minio-core/src/main/java/cn/herodotus/oss/minio/core/converter/ResponseToObjectWriteDomainConverter.java b/oss-minio/minio-core/src/main/java/cn/herodotus/oss/minio/core/converter/ResponseToObjectWriteDomainConverter.java
index 8aa719a1..c9cdce52 100644
--- a/oss-minio/minio-core/src/main/java/cn/herodotus/oss/minio/core/converter/ResponseToObjectWriteDomainConverter.java
+++ b/oss-minio/minio-core/src/main/java/cn/herodotus/oss/minio/core/converter/ResponseToObjectWriteDomainConverter.java
@@ -28,6 +28,7 @@
import cn.herodotus.oss.minio.core.domain.ObjectWriteDomain;
import cn.herodotus.oss.minio.core.utils.ConverterUtils;
import io.minio.ObjectWriteResponse;
+import org.apache.commons.lang3.ObjectUtils;
import org.springframework.core.convert.converter.Converter;
/**
@@ -39,13 +40,17 @@
public class ResponseToObjectWriteDomainConverter implements Converter
- * · 添加的Object大小不能超过5 TB。
- * · 默认情况下,如果已存在同名Object且对该Object有访问权限,则新添加的Object将覆盖原有的Object,并返回200 OK。
- * · OSS没有文件夹的概念,所有资源都是以文件来存储,但您可以通过创建一个以正斜线(/)结尾,大小为0的Object来创建模拟文件夹。
- *
- * @param bucketName 存储桶名称
- * @param objectName 对象名称
- * @param stream 文件流
- * @param objectSize 对象大小
- * @param partSize 分片大小
+ * @param bucketName 存储桶名称
+ * @param objectName 对象名称
+ * @param stream 文件流
+ * @param objectSize 对象大小
+ * @param contentType 内容类型
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String objectName, BufferedInputStream stream, long objectSize, long partSize) {
- return putObject(bucketName, null, objectName, stream, objectSize, partSize);
+ public ObjectWriteResponse putObject(String bucketName, String objectName, InputStream stream, long objectSize, String contentType) {
+ return putObject(bucketName, null, objectName, stream, objectSize, -1 , contentType);
}
/**
@@ -1039,16 +1023,16 @@ public ObjectWriteResponse putObject(String bucketName, String objectName, Buffe
* · 默认情况下,如果已存在同名Object且对该Object有访问权限,则新添加的Object将覆盖原有的Object,并返回200 OK。
* · OSS没有文件夹的概念,所有资源都是以文件来存储,但您可以通过创建一个以正斜线(/)结尾,大小为0的Object来创建模拟文件夹。
*
- * @param bucketName 存储桶名称
- * @param region 区域
- * @param objectName 对象名称
- * @param stream 文件流
- * @param objectSize 对象大小
- * @param partSize 分片大小
+ * @param bucketName 存储桶名称
+ * @param objectName 对象名称
+ * @param stream 文件流
+ * @param objectSize 对象大小
+ * @param partSize 分片大小
+ * @param contentType 内容类型
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String region, String objectName, BufferedInputStream stream, long objectSize, long partSize) {
- return putObject(bucketName, region, objectName, stream, objectSize, partSize, null);
+ public ObjectWriteResponse putObject(String bucketName, String objectName, InputStream stream, long objectSize, long partSize, String contentType) {
+ return putObject(bucketName, null, objectName, stream, objectSize, partSize, contentType);
}
/**
@@ -1067,7 +1051,7 @@ public ObjectWriteResponse putObject(String bucketName, String region, String ob
* @param contentType 内容类型
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String region, String objectName, BufferedInputStream stream, long objectSize, long partSize, String contentType) {
+ public ObjectWriteResponse putObject(String bucketName, String region, String objectName, InputStream stream, long objectSize, long partSize, String contentType) {
return putObject(bucketName, region, objectName, stream, objectSize, partSize, contentType, false);
}
@@ -1088,7 +1072,7 @@ public ObjectWriteResponse putObject(String bucketName, String region, String ob
* @param legalHold 是否保持
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String region, String objectName, BufferedInputStream stream, long objectSize, long partSize, String contentType, boolean legalHold) {
+ public ObjectWriteResponse putObject(String bucketName, String region, String objectName, InputStream stream, long objectSize, long partSize, String contentType, boolean legalHold) {
return putObject(bucketName, region, objectName, stream, objectSize, partSize, contentType, legalHold, null);
}
@@ -1110,7 +1094,7 @@ public ObjectWriteResponse putObject(String bucketName, String region, String ob
* @param retention 保存设置
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String region, String objectName, BufferedInputStream stream, long objectSize, long partSize, String contentType, boolean legalHold, Retention retention) {
+ public ObjectWriteResponse putObject(String bucketName, String region, String objectName, InputStream stream, long objectSize, long partSize, String contentType, boolean legalHold, Retention retention) {
return putObject(bucketName, region, objectName, stream, objectSize, partSize, contentType, legalHold, retention, null);
}
@@ -1133,7 +1117,7 @@ public ObjectWriteResponse putObject(String bucketName, String region, String ob
* @param tags 标签
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String region, String objectName, BufferedInputStream stream, long objectSize, long partSize, String contentType, boolean legalHold, Retention retention, Tags tags) {
+ public ObjectWriteResponse putObject(String bucketName, String region, String objectName, InputStream stream, long objectSize, long partSize, String contentType, boolean legalHold, Retention retention, Tags tags) {
return putObject(bucketName, region, objectName, stream, objectSize, partSize, contentType, legalHold, retention, tags, null);
}
@@ -1157,7 +1141,7 @@ public ObjectWriteResponse putObject(String bucketName, String region, String ob
* @param sse 服务加密
* @return {@link ObjectWriteResponse}
*/
- public ObjectWriteResponse putObject(String bucketName, String region, String objectName, BufferedInputStream stream, long objectSize, long partSize, String contentType, boolean legalHold, Retention retention, Tags tags, ServerSideEncryption sse) {
+ public ObjectWriteResponse putObject(String bucketName, String region, String objectName, InputStream stream, long objectSize, long partSize, String contentType, boolean legalHold, Retention retention, Tags tags, ServerSideEncryption sse) {
return putObject(PutObjectArgs.builder()
.bucket(bucketName)
.region(region)
diff --git a/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/controller/ObjectStreamController.java b/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/controller/ObjectStreamController.java
index 0837abd0..37f52398 100644
--- a/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/controller/ObjectStreamController.java
+++ b/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/controller/ObjectStreamController.java
@@ -26,6 +26,7 @@
package cn.herodotus.oss.minio.scenario.controller;
import cn.herodotus.engine.rest.core.annotation.Idempotent;
+import cn.herodotus.oss.minio.core.domain.ObjectWriteDomain;
import cn.herodotus.oss.minio.scenario.request.ObjectDownloadRequest;
import cn.herodotus.oss.minio.scenario.service.ObjectStreamService;
import io.swagger.v3.oas.annotations.Operation;
@@ -36,14 +37,13 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
+import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@@ -90,4 +90,22 @@ public void download(@Validated @RequestBody ObjectDownloadRequest request, Http
log.error("[Herodotus] |- Download file from minio catch error", e);
}
}
+
+ @Idempotent
+ @Operation(summary = "文件上传", description = "普通的文件上传操作接口",
+ requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = "application/json")),
+ responses = {
+ @ApiResponse(description = "所有对象", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectWriteDomain.class))),
+ @ApiResponse(responseCode = "200", description = "操作成功"),
+ @ApiResponse(responseCode = "500", description = "操作失败"),
+ @ApiResponse(responseCode = "503", description = "Minio Server无法访问或未启动")
+ })
+ @Parameters({
+ @Parameter(name = "bucketName", required = true, description = "存储桶名称"),
+ @Parameter(name = "file", required = true, description = "文件", schema = @Schema(implementation = MultipartFile.class))
+ })
+ @PostMapping("/upload")
+ public ObjectWriteDomain upload(@RequestParam(value = "bucketName") String bucketName, @RequestPart(value = "file") MultipartFile file, HttpServletRequest request) {
+ return objectStreamService.upload(bucketName, file);
+ }
}
diff --git a/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/service/ObjectStreamService.java b/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/service/ObjectStreamService.java
index 6bddcc9d..16e4521d 100644
--- a/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/service/ObjectStreamService.java
+++ b/oss-minio/minio-sdk-scenario/src/main/java/cn/herodotus/oss/minio/scenario/service/ObjectStreamService.java
@@ -25,12 +25,20 @@
package cn.herodotus.oss.minio.scenario.service;
+import cn.herodotus.oss.minio.core.converter.ResponseToObjectWriteDomainConverter;
+import cn.herodotus.oss.minio.core.domain.ObjectWriteDomain;
+import cn.herodotus.oss.minio.core.exception.MinioIOException;
import cn.herodotus.oss.minio.logic.service.ObjectService;
+import io.minio.ObjectWriteResponse;
import io.minio.StatObjectResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.convert.converter.Converter;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
@@ -48,10 +56,14 @@
@Service
public class ObjectStreamService {
+ private static final Logger log = LoggerFactory.getLogger(ObjectStreamService.class);
+
private final ObjectService objectService;
+ private final Converter
-
+
diff --git a/oss-bom/pom.xml b/oss-bom/pom.xml
index fc5909b0..9c616a83 100644
--- a/oss-bom/pom.xml
+++ b/oss-bom/pom.xml
@@ -31,7 +31,7 @@