Search in sources :

Example 1 with OssException

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

the class OssClient method createBucket.

public void createBucket() {
    try {
        String bucketName = properties.getBucketName();
        if (client.doesBucketExistV2(bucketName)) {
            return;
        }
        CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
        createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
        client.createBucket(createBucketRequest);
        client.setBucketPolicy(bucketName, getPolicy(bucketName, PolicyType.READ));
    } catch (Exception e) {
        throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]");
    }
}
Also used : CreateBucketRequest(com.amazonaws.services.s3.model.CreateBucketRequest) OssException(com.ruoyi.common.oss.exception.OssException) OssException(com.ruoyi.common.oss.exception.OssException)

Example 2 with OssException

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

the class OssClient method upload.

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

Example 3 with OssException

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

the class OssFactory method refresh.

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

Aggregations

OssException (com.ruoyi.common.oss.exception.OssException)3 CreateBucketRequest (com.amazonaws.services.s3.model.CreateBucketRequest)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 OssClient (com.ruoyi.common.oss.core.OssClient)1 OssProperties (com.ruoyi.common.oss.properties.OssProperties)1