From c7fa563f9a951c647725c3d0e02b7bce366d23ea Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Tue, 23 Dec 2025 11:02:51 +0800
Subject: [PATCH] 增加设置相机模式接口 取消拍照录像业务中设置
---
ard-oss/src/main/java/com/ard/oss/service/impl/OssServiceContext.java | 36 +++++++++++++++++++++---------------
1 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/ard-oss/src/main/java/com/ard/oss/service/impl/OssServiceContext.java b/ard-oss/src/main/java/com/ard/oss/service/impl/OssServiceContext.java
index cc61355..2ee3fdc 100644
--- a/ard-oss/src/main/java/com/ard/oss/service/impl/OssServiceContext.java
+++ b/ard-oss/src/main/java/com/ard/oss/service/impl/OssServiceContext.java
@@ -12,6 +12,7 @@
import io.minio.PutObjectArgs;
import lombok.Cleanup;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -139,13 +140,7 @@
// 上传文件到 Minio
this.ossService.putObject(bucket, objectName, inputStream, contentType);
- // ✅ 拼接永久 URL(不带 presigned 过期参数)
- String baseUrl = OssConfiguration.endpoint;
- if (!baseUrl.endsWith("/")) {
- baseUrl += "/";
- }
-
- return baseUrl + bucket + "/" + objectName;
+ return buildUrl(bucket, objectName);
} catch (Exception e) {
throw new IOException("Upload failed: " + e.getMessage(), e);
}
@@ -153,21 +148,23 @@
public String upload(String bucket, String objectKey, InputStream input) {
try {
-
// 上传文件
this.ossService.putObject(bucket, objectKey, input);
-
- // ✅ 构建永久访问 URL
- String baseUrl = OssConfiguration.endpoint;
- if (!baseUrl.endsWith("/")) {
- baseUrl += "/";
- }
- return baseUrl + bucket + "/" + objectKey;
+ return buildUrl(bucket, objectKey);
} catch (Exception e) {
throw new RuntimeException("Upload failed: " + e.getMessage(), e);
}
}
+ public String upload(String bucket, String objectKey, InputStream input, String contentType) {
+ try {
+ // 上传文件时指定 Content-Type
+ this.ossService.putObject(bucket, objectKey, input, contentType);
+ return buildUrl(bucket, objectKey);
+ } catch (Exception e) {
+ throw new RuntimeException("Upload failed: " + e.getMessage(), e);
+ }
+ }
// 获取文件 MIME 类型
public String getMimeTypeByExtension(String fileName) {
// 获取文件扩展名
@@ -200,4 +197,13 @@
}
}
+ // 构建url
+ private String buildUrl(String bucket, String key) {
+ String base = OssConfiguration.endpoint;
+ if (!base.endsWith("/")) {
+ base += "/";
+ }
+ return base + bucket + "/" + key;
+ }
+
}
--
Gitblit v1.9.3