use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.
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;
}
use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.
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() + "]");
}
}
use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.
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();
}
use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.
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;
}
use of com.ruoyi.oss.exception.OssException in project RuoYi-Flowable-Plus by KonBAI-Q.
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());
}
}
Aggregations