Search in sources :

Example 21 with OssException

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

the class QcloudOssStrategy method init.

@Override
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 (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
            clientConfig.setHttpProtocol(HttpProtocol.https);
        } else {
            clientConfig.setHttpProtocol(HttpProtocol.http);
        }
        client = new COSClient(credentials, clientConfig);
        createBucket();
    } catch (Exception e) {
        throw new OssException("腾讯云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
    }
    isInit = true;
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 22 with OssException

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

the class QiniuOssStrategy method upload.

@Override
public UploadResult upload(byte[] data, String path, String contentType) {
    try {
        String token = auth.uploadToken(properties.getBucketName());
        Response res = uploadManager.put(data, path, token, null, contentType, false);
        if (!res.isOK()) {
            throw new RuntimeException("上传七牛出错:" + res.error);
        }
    } catch (Exception e) {
        throw new OssException("上传文件失败,请核对七牛配置信息:[" + e.getMessage() + "]");
    }
    return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build();
}
Also used : Response(com.qiniu.http.Response) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 23 with OssException

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

the class QiniuOssStrategy method init.

@Override
public void init(OssProperties ossProperties) {
    super.init(ossProperties);
    try {
        Configuration config = new Configuration(getRegion(properties.getRegion()));
        // https设置
        config.useHttpsDomains = OssConstant.IS_HTTPS.equals(properties.getIsHttps());
        uploadManager = new UploadManager(config);
        auth = Auth.create(properties.getAccessKey(), properties.getSecretKey());
        bucketManager = new BucketManager(auth, config);
        createBucket();
    } catch (Exception e) {
        throw new OssException("七牛云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
    }
    isInit = true;
}
Also used : Configuration(com.qiniu.storage.Configuration) BucketManager(com.qiniu.storage.BucketManager) UploadManager(com.qiniu.storage.UploadManager) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 24 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.

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 25 with OssException

use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.

the class MinioOssStrategy method createBucket.

@Override
public void createBucket() {
    try {
        String bucketName = properties.getBucketName();
        boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
        if (exists) {
            return;
        }
        // 不存在就创建桶
        minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
        minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucketName).config(getPolicy(bucketName, PolicyType.READ)).build());
    } catch (Exception e) {
        throw new OssException("创建Bucket失败, 请核对Minio配置信息:[" + e.getMessage() + "]");
    }
}
Also used : OssException(com.ruoyi.oss.exception.OssException) 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