| | |
| | | import com.qcloud.cos.model.*; |
| | | import com.qcloud.cos.region.Region; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | 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.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Component |
| | | public class QcloudOssStrategy extends AbstractOssStrategy { |
| | | |
| | | private COSClient client; |
| | | |
| | | @Override |
| | | public void init(OssProperties cloudStorageProperties) { |
| | | properties = cloudStorageProperties; |
| | | public void init(OssProperties ossProperties) { |
| | | super.init(ossProperties); |
| | | try { |
| | | COSCredentials credentials = new BasicCOSCredentials( |
| | | properties.getAccessKey(), properties.getSecretKey()); |
| | |
| | | ClientConfig clientConfig = new ClientConfig(); |
| | | // 设置bucket所在的区域,华南:gz 华北:tj 华东:sh |
| | | clientConfig.setRegion(new Region(properties.getRegion())); |
| | | if ("Y".equals(properties.getIsHttps())) { |
| | | if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) { |
| | | clientConfig.setHttpProtocol(HttpProtocol.https); |
| | | } else { |
| | | clientConfig.setHttpProtocol(HttpProtocol.http); |
| | |
| | | } catch (Exception e) { |
| | | throw new OssException("腾讯云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]"); |
| | | } |
| | | isInit = true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getServiceType() { |
| | | return OssEnumd.QCLOUD.getValue(); |
| | | public OssEnumd getServiceType() { |
| | | return OssEnumd.QCLOUD; |
| | | } |
| | | |
| | | @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 |