疯狂的狮子li
2021-07-23 7114fc27207ea8f8aca86dd91ff2acfe470c9349
ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/MinioCloudStorageServiceImpl.java
@@ -39,18 +39,28 @@
            .endpoint(this.properties.getEndpoint())
            .credentials(this.properties.getAccessKey(), this.properties.getSecretKey())
            .build();
         String bucketName = this.properties.getBucketName();
         createBucket();
      } catch (Exception e) {
         throw new IllegalArgumentException("Minio存储配置错误! 请检查系统配置!");
      }
   }
   @Override
   public void createBucket() {
      try {
         String bucketName = properties.getBucketName();
         boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
         if (exists) {
            return;
         }
         // 不存在就创建桶
         if (!exists) {
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
            minioClient.setBucketPolicy(SetBucketPolicyArgs.builder()
               .bucket(bucketName)
               .config(getPolicy(bucketName, PolicyType.READ))
               .build());
         }
      } catch (Exception e) {
         throw new IllegalArgumentException("Minio存储配置错误! 请检查系统配置!");
         throw new OssException("创建Bucket失败, 请核对Minio配置信息");
      }
   }
@@ -76,12 +86,12 @@
      } catch (Exception e) {
         throw new OssException("上传文件失败,请核对Minio配置信息");
      }
      return new UploadResult().setUrl(getBaseUrl() + path).setFilename(path);
      return new UploadResult().setUrl(getEndpointLink() + "/" + path).setFilename(path);
   }
   @Override
   public void delete(String path) {
      path = path.replace(getBaseUrl(), "");
      path = path.replace(getEndpointLink() + "/", "");
      try {
         minioClient.removeObject(RemoveObjectArgs.builder()
            .bucket(properties.getBucketName())
@@ -107,8 +117,9 @@
      OssFactory.register(getServiceType(), this);
   }
   private String getBaseUrl() {
      return properties.getEndpoint() + "/" + properties.getBucketName() + "/";
   @Override
   public String getEndpointLink() {
      return properties.getEndpoint() + "/" + properties.getBucketName();
   }
   private String getPolicy(String bucketName, PolicyType policyType) {