Search in sources :

Example 16 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Vue-Plus by JavaLionLi.

the class OssFactory method refresh.

private static void refresh(String type) {
    Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + type);
    OssProperties properties = JsonUtils.parseObject(json.toString(), OssProperties.class);
    if (properties == null) {
        throw new OssException("系统异常, '" + type + "'配置信息不存在!");
    }
    getStrategy(type).init(properties);
}
Also used : OssProperties(com.ruoyi.oss.properties.OssProperties) OssException(com.ruoyi.oss.exception.OssException)

Example 17 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Vue-Plus by JavaLionLi.

the class AliyunOssStrategy method getEndpointLink.

@Override
public String getEndpointLink() {
    String endpoint = properties.getEndpoint();
    StringBuilder sb = new StringBuilder(endpoint);
    if (StringUtils.containsAnyIgnoreCase(endpoint, "http://")) {
        sb.insert(7, properties.getBucketName() + ".");
    } else if (StringUtils.containsAnyIgnoreCase(endpoint, "https://")) {
        sb.insert(8, properties.getBucketName() + ".");
    } else {
        throw new OssException("Endpoint配置错误");
    }
    return sb.toString();
}
Also used : OssException(com.ruoyi.oss.exception.OssException)

Example 18 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Vue-Plus by JavaLionLi.

the class AliyunOssStrategy method upload.

@Override
public UploadResult upload(InputStream inputStream, String path, String contentType) {
    try {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType(contentType);
        client.putObject(new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata));
    } catch (Exception e) {
        throw new OssException("上传文件失败,请检查阿里云配置信息:[" + e.getMessage() + "]");
    }
    return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build();
}
Also used : ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) PutObjectRequest(com.aliyun.oss.model.PutObjectRequest) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 19 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Vue-Plus by JavaLionLi.

the class MinioOssStrategy method init.

@Override
public void init(OssProperties ossProperties) {
    super.init(ossProperties);
    try {
        MinioClient.Builder builder = MinioClient.builder();
        if (OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) {
            HttpUrl url = HttpUtils.getBaseUrl(properties.getEndpoint()).newBuilder().scheme("https").build();
            builder.endpoint(url);
        } else {
            builder.endpoint(properties.getEndpoint());
        }
        minioClient = builder.credentials(properties.getAccessKey(), properties.getSecretKey()).build();
        createBucket();
    } catch (Exception e) {
        throw new OssException("Minio存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
    }
    isInit = true;
}
Also used : HttpUrl(okhttp3.HttpUrl) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 20 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Vue-Plus by JavaLionLi.

the class QcloudOssStrategy method getEndpointLink.

@Override
public String getEndpointLink() {
    String endpoint = properties.getEndpoint();
    StringBuilder sb = new StringBuilder(endpoint);
    if (StringUtils.containsAnyIgnoreCase(endpoint, "http://")) {
        sb.insert(7, properties.getBucketName() + ".");
    } else if (StringUtils.containsAnyIgnoreCase(endpoint, "https://")) {
        sb.insert(8, properties.getBucketName() + ".");
    } else {
        throw new OssException("Endpoint配置错误");
    }
    return sb.toString();
}
Also used : OssException(com.ruoyi.oss.exception.OssException)

Aggregations

OssException (com.ruoyi.oss.exception.OssException)32 Response (com.qiniu.http.Response)4 ClientConfiguration (com.aliyun.oss.ClientConfiguration)2 OSSClient (com.aliyun.oss.OSSClient)2 DefaultCredentialProvider (com.aliyun.oss.common.auth.DefaultCredentialProvider)2 CreateBucketRequest (com.aliyun.oss.model.CreateBucketRequest)2 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)2 PutObjectRequest (com.aliyun.oss.model.PutObjectRequest)2 COSClient (com.qcloud.cos.COSClient)2 ClientConfig (com.qcloud.cos.ClientConfig)2 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)2 COSCredentials (com.qcloud.cos.auth.COSCredentials)2 Region (com.qcloud.cos.region.Region)2 BucketManager (com.qiniu.storage.BucketManager)2 Configuration (com.qiniu.storage.Configuration)2 UploadManager (com.qiniu.storage.UploadManager)2 OssEnumd (com.ruoyi.oss.enumd.OssEnumd)2 OssProperties (com.ruoyi.oss.properties.OssProperties)2 AbstractOssStrategy (com.ruoyi.oss.service.abstractd.AbstractOssStrategy)2 HttpUrl (okhttp3.HttpUrl)2