# 阿里云OSS

# 核心配置

# Yaml配置

# ========================= HaiChuang Settings =========================
haichuang:
  sdk:
    aliyunoss:
      # AccessKeyId
      access-key-id: xxx
      # AccessKeySecret
      access-key-secret: xxx
      # BucketName
      bucket-name: xxx
      # Endpoint地域节点
      endpoint: xxx
1
2
3
4
5
6
7
8
9
10
11
12

提示

可通过AliYunOssProperties (opens new window) 中的getBucketDomain()方法获取BucketDomain(访问域名前缀)

@Autowired
private AliYunOssProperties aliYunOssProperties;

@Test
void getBucketDomain() {
    System.out.println(aliYunOssProperties.getBucketDomain());
}
1
2
3
4
5
6
7

# 核心注解

包路径:pro.haichuang.framework.sdk.aliyunoss.annotation (opens new window)

# @EnableOssUrlConvert (opens new window)

  • 注解名称:启用阿里云OSS地址转换
  • 实现功能:该注解标注在Controller方法上,代表该方法启用OSS地址解析,该注解与@OssUrl一起使用
  • 标注位置:Controller方法上

# @OssUrl (opens new window)

  • 注解名称:阿里云OSS地址转换
  • 实现功能:该注解标注在Controller方法形参上或实体内, 将会在请求时自动去掉OSS请求前缀, 在响应时自动添加OSS请求前缀
  • 标注位置:指定方法形参或类字段上
  • 使用方法:
    1. Controller方法上标注@EnableOssUrlConvert注解
    2. 在形参对象类中标注@OssUrl注解

# 核心Service

# AliYunOssService (opens new window)

全限定名:pro.haichuang.framework.sdk.aliyunoss.service.AliYunOssService (opens new window)

阿里云OSS核心Service

该类为阿里云OSS核心Service,封装了常用的方法

警告

所有OSS相关操作必须使用AliYunOssService接口

# DefaultAliYunOssServiceImpl (opens new window)

全限定名:pro.haichuang.framework.sdk.aliyunoss.service.DefaultAliYunOssServiceImpl (opens new window)

阿里云OSS核心Service默认实现

该类为阿里云OSS核心Service默认实现,已默认注入到Spring中,支持自定义实现(需要手动注入到Spring中)

# 核心工具类

# AliYunOssUtils (opens new window)

全限定名:pro.haichuang.framework.sdk.aliyunoss.util.AliYunOssUtils (opens new window)

阿里云OSS工具类

该类为阿里云OSS工具类,基于第三方二次封装,推荐使用AliYunOssUtils进行操作

# 👇Example👇

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private AliYunOssService aliYunOssService;
    
    ......
}
1
2
3
4
5
6
7
8
9
Last Updated: 12/14/2021, 5:11:19 PM