Search in sources :

Example 6 with OssException

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

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

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

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

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

the class OssFactory method instance.

/**
 * 根据类型获取实例
 */
public static IOssStrategy instance(String type) {
    OssEnumd enumd = OssEnumd.find(type);
    if (enumd == null) {
        throw new OssException("文件存储服务类型无法找到!");
    }
    AbstractOssStrategy strategy = getStrategy(type);
    if (!strategy.isInit) {
        refresh(type);
    }
    return strategy;
}
Also used : OssEnumd(com.ruoyi.oss.enumd.OssEnumd) AbstractOssStrategy(com.ruoyi.oss.service.abstractd.AbstractOssStrategy) OssException(com.ruoyi.oss.exception.OssException)

Example 9 with OssException

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

the class AliyunOssStrategy method init.

@Override
public void init(OssProperties ossProperties) {
    super.init(ossProperties);
    try {
        ClientConfiguration configuration = new ClientConfiguration();
        if (OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) {
            configuration.setProtocol(Protocol.HTTPS);
        }
        DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider(properties.getAccessKey(), properties.getSecretKey());
        client = new OSSClient(properties.getEndpoint(), credentialProvider, configuration);
        createBucket();
    } catch (Exception e) {
        throw new OssException("阿里云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
    }
    isInit = true;
}
Also used : OSSClient(com.aliyun.oss.OSSClient) DefaultCredentialProvider(com.aliyun.oss.common.auth.DefaultCredentialProvider) ClientConfiguration(com.aliyun.oss.ClientConfiguration) OssException(com.ruoyi.oss.exception.OssException) OssException(com.ruoyi.oss.exception.OssException)

Example 10 with OssException

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

the class AliyunOssStrategy 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 : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) 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