| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.oss.constant.OssConstant; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.OssEnumd; |
| | | import com.ruoyi.oss.enumd.PolicyType; |
| | |
| | | import com.ruoyi.oss.service.abstractd.AbstractOssStrategy; |
| | | import io.minio.*; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Component |
| | | public class MinioOssStrategy extends AbstractOssStrategy { |
| | | |
| | | private MinioClient minioClient; |
| | | |
| | | @Override |
| | | public void init(OssProperties cloudStorageProperties) { |
| | | properties = cloudStorageProperties; |
| | | public void init(OssProperties ossProperties) { |
| | | super.init(ossProperties); |
| | | try { |
| | | minioClient = MinioClient.builder() |
| | | .endpoint(properties.getEndpoint()) |
| | | .endpoint(properties.getEndpoint(), 443, OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) |
| | | .credentials(properties.getAccessKey(), properties.getSecretKey()) |
| | | .build(); |
| | | createBucket(); |
| | | } catch (Exception e) { |
| | | throw new OssException("Minio存储配置错误! 请检查系统配置:[" + e.getMessage() + "]"); |
| | | } |
| | | isInit = true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getServiceType() { |
| | | return OssEnumd.MINIO.getValue(); |
| | | public OssEnumd getServiceType() { |
| | | return OssEnumd.MINIO; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } catch (Exception e) { |
| | | throw new OssException("上传文件失败,请核对Minio配置信息:[" + e.getMessage() + "]"); |
| | | } |
| | | return new UploadResult().setUrl(getEndpointLink() + "/" + path).setFilename(path); |
| | | return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build(); |
| | | } |
| | | |
| | | @Override |