| | |
| | | import com.qiniu.storage.Region; |
| | | import com.qiniu.storage.UploadManager; |
| | | import com.qiniu.util.Auth; |
| | | import com.ruoyi.oss.constant.OssConstant; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.OssEnumd; |
| | | import com.ruoyi.oss.exception.OssException; |
| | | import com.ruoyi.oss.properties.OssProperties; |
| | | import com.ruoyi.oss.service.abstractd.AbstractOssStrategy; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.InputStream; |
| | | |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Component |
| | | public class QiniuOssStrategy extends AbstractOssStrategy { |
| | | |
| | | private UploadManager uploadManager; |
| | | private BucketManager bucketManager; |
| | | private Auth auth; |
| | | |
| | | |
| | | @Override |
| | | public void init(OssProperties cloudStorageProperties) { |
| | | properties = cloudStorageProperties; |
| | | public void init(OssProperties ossProperties) { |
| | | super.init(ossProperties); |
| | | try { |
| | | Configuration config = new Configuration(getRegion(properties.getRegion())); |
| | | // https设置 |
| | | config.useHttpsDomains = false; |
| | | config.useHttpsDomains = "Y".equals(properties.getIsHttps()); |
| | | config.useHttpsDomains = OssConstant.IS_HTTPS.equals(properties.getIsHttps()); |
| | | uploadManager = new UploadManager(config); |
| | | auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); |
| | | String bucketName = properties.getBucketName(); |
| | | bucketManager = new BucketManager(auth, config); |
| | | |
| | | if (!ArrayUtil.contains(bucketManager.buckets(), bucketName)) { |
| | | bucketManager.createBucket(bucketName, properties.getRegion()); |
| | | } |
| | | createBucket(); |
| | | } catch (Exception e) { |
| | | throw new OssException("七牛云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]"); |
| | | } |
| | | isInit = true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getServiceType() { |
| | | return OssEnumd.QINIU.getValue(); |
| | | public OssEnumd getServiceType() { |
| | | return OssEnumd.QINIU; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } catch (Exception e) { |
| | | throw new OssException("上传文件失败,请核对七牛配置信息:[" + e.getMessage() + "]"); |
| | | } |
| | | return new UploadResult().setUrl(getEndpointLink() + "/" + path).setFilename(path); |
| | | return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build(); |
| | | } |
| | | |
| | | @Override |