设置MINIO上传的mediaType,以便于图片等文件能在浏览器直接浏览。
如果未获取到mediaType,则Content-Type设置为 application/octet-stream
This commit is contained in:
parent
2e8a5f8591
commit
476646d1e0
|
@ -4,11 +4,15 @@ import io.minio.BucketExistsArgs;
|
||||||
import io.minio.MakeBucketArgs;
|
import io.minio.MakeBucketArgs;
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import io.minio.PutObjectArgs;
|
import io.minio.PutObjectArgs;
|
||||||
|
import net.maku.framework.common.constant.Constant;
|
||||||
import net.maku.framework.common.exception.ServerException;
|
import net.maku.framework.common.exception.ServerException;
|
||||||
import net.maku.storage.properties.StorageProperties;
|
import net.maku.storage.properties.StorageProperties;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.MediaTypeFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minio存储
|
* Minio存储
|
||||||
|
@ -40,9 +44,16 @@ public class MinioStorageService extends StorageService {
|
||||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(properties.getMinio().getBucketName()).build());
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(properties.getMinio().getBucketName()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String contentType = Constant.CONTENTTYPE_OCTET_STREAM;
|
||||||
|
Optional<MediaType> mediaType = MediaTypeFactory.getMediaType(path);
|
||||||
|
if (mediaType.isPresent()) {
|
||||||
|
contentType = mediaType.get().toString();
|
||||||
|
}
|
||||||
|
|
||||||
minioClient.putObject(
|
minioClient.putObject(
|
||||||
PutObjectArgs.builder()
|
PutObjectArgs.builder()
|
||||||
.bucket(properties.getMinio().getBucketName())
|
.bucket(properties.getMinio().getBucketName())
|
||||||
|
.contentType(contentType)
|
||||||
.object(path)
|
.object(path)
|
||||||
.stream(inputStream, inputStream.available(), -1)
|
.stream(inputStream, inputStream.available(), -1)
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -48,5 +48,9 @@ public interface Constant {
|
||||||
* pgsql的driver
|
* pgsql的driver
|
||||||
*/
|
*/
|
||||||
String PGSQL_DRIVER = "org.postgresql.Driver";
|
String PGSQL_DRIVER = "org.postgresql.Driver";
|
||||||
|
/**
|
||||||
|
* Content-Type
|
||||||
|
*/
|
||||||
|
String CONTENTTYPE_OCTET_STREAM = "application/octet-stream";
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user