疯狂的狮子li
2021-11-17 eb844e3260657b6bb9de03c1e5feca50bdf8190d
ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java
@@ -24,7 +24,7 @@
   private UploadManager uploadManager;
   private BucketManager bucketManager;
   private String token;
   private Auth auth;
   @Override
   public void init(CloudStorageProperties cloudStorageProperties) {
@@ -35,16 +35,15 @@
         config.useHttpsDomains = false;
         config.useHttpsDomains = "Y".equals(properties.getIsHttps());
         uploadManager = new UploadManager(config);
         Auth auth = Auth.create(properties.getAccessKey(), properties.getSecretKey());
         auth = Auth.create(properties.getAccessKey(), properties.getSecretKey());
         String bucketName = properties.getBucketName();
         token = auth.uploadToken(bucketName);
         bucketManager = new BucketManager(auth, config);
         if (!ArrayUtil.contains(bucketManager.buckets(), bucketName)) {
            bucketManager.createBucket(bucketName, properties.getRegion());
         }
      } catch (Exception e) {
         throw new OssException("七牛云存储配置错误! 请检查系统配置!");
         throw new OssException("七牛云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
      }
   }
@@ -57,7 +56,7 @@
         }
         bucketManager.createBucket(bucketName, properties.getRegion());
      } catch (Exception e) {
         throw new OssException("创建Bucket失败, 请核对七牛云配置信息");
         throw new OssException("创建Bucket失败, 请核对七牛云配置信息:[" + e.getMessage() + "]");
      }
   }
@@ -69,12 +68,13 @@
   @Override
   public UploadResult upload(byte[] data, String path, String contentType) {
      try {
         Response res = uploadManager.put(data, path, token, null, contentType, false);
            String token = auth.uploadToken(properties.getBucketName());
            Response res = uploadManager.put(data, path, token, null, contentType, false);
         if (!res.isOK()) {
            throw new RuntimeException("上传七牛出错:" + res.toString());
            throw new RuntimeException("上传七牛出错:" + res.error);
         }
      } catch (Exception e) {
         throw new OssException("上传文件失败,请核对七牛配置信息");
         throw new OssException("上传文件失败,请核对七牛配置信息:[" + e.getMessage() + "]");
      }
      return new UploadResult().setUrl(getEndpointLink() + "/" + path).setFilename(path);
   }
@@ -85,7 +85,7 @@
         path = path.replace(getEndpointLink() + "/", "");
         Response res = bucketManager.delete(properties.getBucketName(), path);
         if (!res.isOK()) {
            throw new RuntimeException("删除七牛文件出错:" + res.toString());
            throw new RuntimeException("删除七牛文件出错:" + res.error);
         }
      } catch (Exception e) {
         throw new OssException(e.getMessage());