Search in sources :

Example 11 with OssException

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

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)

Example 12 with OssException

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

the class QcloudOssStrategy method createBucket.

@Override
public void createBucket() {
    try {
        String bucketName = properties.getBucketName();
        if (client.doesBucketExist(bucketName)) {
            return;
        }
        CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
        createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
        client.createBucket(createBucketRequest);
    } catch (Exception e) {
        throw new OssException("创建Bucket失败, 请核对腾讯云配置信息:[" + e.getMessage() + "]");
    }
}
Also used : OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 13 with OssException

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

the class QcloudOssStrategy 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 : OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 14 with OssException

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

the class QiniuOssStrategy method createBucket.

@Override
public void createBucket() {
    try {
        String bucketName = properties.getBucketName();
        if (ArrayUtil.contains(bucketManager.buckets(), bucketName)) {
            return;
        }
        bucketManager.createBucket(bucketName, properties.getRegion());
    } catch (Exception e) {
        throw new OssException("创建Bucket失败, 请核对七牛云配置信息:[" + e.getMessage() + "]");
    }
}
Also used : OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 15 with OssException

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

the class QiniuOssStrategy method delete.

@Override
public void delete(String path) {
    try {
        path = path.replace(getEndpointLink() + "/", "");
        Response res = bucketManager.delete(properties.getBucketName(), path);
        if (!res.isOK()) {
            throw new RuntimeException("删除七牛文件出错:" + res.error);
        }
    } catch (Exception e) {
        throw new OssException(e.getMessage());
    }
}
Also used : Response(com.qiniu.http.Response) 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