From 476646d1e0b865ef26a51893733c1ce1d79ff0ba Mon Sep 17 00:00:00 2001 From: zhuxy Date: Fri, 31 Mar 2023 10:45:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AEMINIO=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=9A=84mediaType=EF=BC=8C=E4=BB=A5=E4=BE=BF=E4=BA=8E=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=AD=89=E6=96=87=E4=BB=B6=E8=83=BD=E5=9C=A8=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E7=9B=B4=E6=8E=A5=E6=B5=8F=E8=A7=88=E3=80=82?= =?UTF-8?q?=20=E5=A6=82=E6=9E=9C=E6=9C=AA=E8=8E=B7=E5=8F=96=E5=88=B0mediaT?= =?UTF-8?q?ype=EF=BC=8C=E5=88=99Content-Type=E8=AE=BE=E7=BD=AE=E4=B8=BA=20?= =?UTF-8?q?application/octet-stream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/maku/storage/service/MinioStorageService.java | 11 +++++++++++ .../net/maku/framework/common/constant/Constant.java | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/maku-boot-system/src/main/java/net/maku/storage/service/MinioStorageService.java b/maku-boot-system/src/main/java/net/maku/storage/service/MinioStorageService.java index 816865d..0add5bf 100644 --- a/maku-boot-system/src/main/java/net/maku/storage/service/MinioStorageService.java +++ b/maku-boot-system/src/main/java/net/maku/storage/service/MinioStorageService.java @@ -4,11 +4,15 @@ import io.minio.BucketExistsArgs; import io.minio.MakeBucketArgs; import io.minio.MinioClient; import io.minio.PutObjectArgs; +import net.maku.framework.common.constant.Constant; import net.maku.framework.common.exception.ServerException; import net.maku.storage.properties.StorageProperties; +import org.springframework.http.MediaType; +import org.springframework.http.MediaTypeFactory; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.Optional; /** * Minio存储 @@ -40,9 +44,16 @@ public class MinioStorageService extends StorageService { minioClient.makeBucket(MakeBucketArgs.builder().bucket(properties.getMinio().getBucketName()).build()); } + String contentType = Constant.CONTENTTYPE_OCTET_STREAM; + Optional mediaType = MediaTypeFactory.getMediaType(path); + if (mediaType.isPresent()) { + contentType = mediaType.get().toString(); + } + minioClient.putObject( PutObjectArgs.builder() .bucket(properties.getMinio().getBucketName()) + .contentType(contentType) .object(path) .stream(inputStream, inputStream.available(), -1) .build() diff --git a/maku-framework/src/main/java/net/maku/framework/common/constant/Constant.java b/maku-framework/src/main/java/net/maku/framework/common/constant/Constant.java index 7e5d7e5..e70936d 100644 --- a/maku-framework/src/main/java/net/maku/framework/common/constant/Constant.java +++ b/maku-framework/src/main/java/net/maku/framework/common/constant/Constant.java @@ -48,5 +48,9 @@ public interface Constant { * pgsql的driver */ String PGSQL_DRIVER = "org.postgresql.Driver"; + /** + * Content-Type + */ + String CONTENTTYPE_OCTET_STREAM = "application/octet-stream"; } \ No newline at end of file -- Gitee