ÎļþÃû´Ó ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QcloudCloudStorageServiceImpl.java ÐÞ¸Ä |
| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.qcloud.cos.COSClient; |
| | | import com.qcloud.cos.ClientConfig; |
| | | import com.qcloud.cos.auth.BasicCOSCredentials; |
| | |
| | | import com.qcloud.cos.http.HttpProtocol; |
| | | import com.qcloud.cos.model.*; |
| | | import com.qcloud.cos.region.Region; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | 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.CloudStorageProperties.QcloudProperties; |
| | | import com.ruoyi.oss.service.abstractd.AbstractCloudStorageService; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.oss.service.abstractd.AbstractCloudStorageStrategy; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | | |
| | | /** |
| | | * è
¾è®¯äºåå¨ |
| | | * è
¾è®¯äºåå¨çç¥ |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Lazy |
| | | @Service |
| | | public class QcloudCloudStorageServiceImpl extends AbstractCloudStorageService implements InitializingBean { |
| | | public class QcloudCloudStorageStrategy extends AbstractCloudStorageStrategy { |
| | | |
| | | private final COSClient client; |
| | | private final QcloudProperties properties; |
| | | |
| | | @Autowired |
| | | public QcloudCloudStorageServiceImpl(CloudStorageProperties properties) { |
| | | this.properties = properties.getQcloud(); |
| | | public QcloudCloudStorageStrategy(CloudStorageProperties cloudStorageProperties) { |
| | | properties = cloudStorageProperties; |
| | | try { |
| | | COSCredentials credentials = new BasicCOSCredentials( |
| | | this.properties.getSecretId(), |
| | | this.properties.getSecretKey()); |
| | | properties.getAccessKey(), properties.getSecretKey()); |
| | | // åå§å客æ·ç«¯é
ç½® |
| | | ClientConfig clientConfig = new ClientConfig(); |
| | | // 设置bucketæå¨çåºåï¼ååï¼gz ååï¼tj åä¸ï¼sh |
| | | clientConfig.setRegion(new Region(this.properties.getRegion())); |
| | | if (this.properties.getIsHttps()) { |
| | | clientConfig.setRegion(new Region(properties.getRegion())); |
| | | if ("Y".equals(properties.getIsHttps())) { |
| | | clientConfig.setHttpProtocol(HttpProtocol.https); |
| | | } else { |
| | | clientConfig.setHttpProtocol(HttpProtocol.http); |
| | |
| | | @Override |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { |
| | | return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | | OssFactory.register(getServiceType(),this); |
| | | } |
| | | |
| | | @Override |