疯狂的狮子li
2021-07-20 a4c019ace2841faa6af14b5373a041464c3dbbde
ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java
@@ -6,11 +6,12 @@
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.ruoyi.oss.entity.UploadResult;
import com.ruoyi.oss.enumd.CloudServiceEnumd;
import com.ruoyi.oss.exception.OssException;
import com.ruoyi.oss.factory.OssFactory;
import com.ruoyi.oss.properties.CloudStorageProperties;
import com.ruoyi.oss.properties.QiniuProperties;
import com.ruoyi.oss.properties.CloudStorageProperties.QiniuProperties;
import com.ruoyi.oss.service.abstractd.AbstractCloudStorageService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,16 +37,20 @@
   @Autowired
   public QiniuCloudStorageServiceImpl(CloudStorageProperties properties) {
      this.properties = properties.getQiniu();
      // z0 z1 z2
      Configuration config = new Configuration(Region.autoRegion());
      // 默认不使用https
      config.useHttpsDomains = false;
      uploadManager = new UploadManager(config);
      Auth auth = Auth.create(
         this.properties.getAccessKey(),
         this.properties.getSecretKey());
      token = auth.uploadToken(this.properties.getBucketName());
      bucketManager = new BucketManager(auth, config);
      try {
         // z0 z1 z2
         Configuration config = new Configuration(Region.autoRegion());
         // 默认不使用https
         config.useHttpsDomains = false;
         uploadManager = new UploadManager(config);
         Auth auth = Auth.create(
            this.properties.getAccessKey(),
            this.properties.getSecretKey());
         token = auth.uploadToken(this.properties.getBucketName());
         bucketManager = new BucketManager(auth, config);
      } catch (Exception e) {
         throw new IllegalArgumentException("七牛云存储配置错误! 请检查系统配置!");
      }
   }
@@ -55,7 +60,7 @@
   }
   @Override
   public String upload(byte[] data, String path) {
   public UploadResult upload(byte[] data, String path, String contentType) {
      try {
         Response res = uploadManager.put(data, path, token);
         if (!res.isOK()) {
@@ -64,7 +69,7 @@
      } catch (Exception e) {
         throw new OssException("上传文件失败,请核对七牛配置信息");
      }
      return this.properties.getDomain() + "/" + path;
      return new UploadResult().setUrl(properties.getDomain() + "/" + path).setFilename(path);
   }
   @Override
@@ -81,13 +86,13 @@
   }
   @Override
   public String uploadSuffix(byte[] data, String suffix) {
      return upload(data, getPath(this.properties.getPrefix(), suffix));
   public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
      return upload(data, getPath(this.properties.getPrefix(), suffix), contentType);
   }
   @Override
   public String uploadSuffix(InputStream inputStream, String suffix) {
      return upload(inputStream, getPath(this.properties.getPrefix(), suffix));
   public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
      return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType);
   }
   @Override