Solon

file-s3-solon-cloud-plugin

v2.7.3 </> markdown

此插件,由社区成员(等風來再離開)贡献

<dependency>
    <groupId>org.noear</groupId>
    <artifactId>file-s3-solon-cloud-plugin</artifactId>
</dependency>

1、描述

分布式扩展插件。基于 aws s3 协议适配的 solon cloud 插件。提供所有 's3' 协议文件存储服务,及本地文件服务。支持多个供应商共存(有点儿聚合的味道)。

2、云端能力接口

接口说明备注
CloudFileService云端文件服务

3、配置示例

solon.cloud.file.s3.file:
  default: 'demo1_bucket' #默认
  buckets:
    demo1_bucket: #所用存储桶( bucket ),必须都先配置好 //且 bucket 须手动先建好
      endpoint: 'https://obs.cn-southwest-2.myhuaweicloud.com' #通过协议,表达是否使用 https?
      regionId: ''
      accessKey: 'xxxx'
      secretKey: 'xxx'
    demo2_bucket:
      endpoint: 'D:/img' # 或 '/data/sss/files' #表示为本地(非本地的,要 http:// 或 https:// 开头)
    demo3_bucket:
      endpoint: 'http://s3.ladydaily.com'
      regionId: ''
      accessKey: 'xxxx'
      secretKey: 'xxx'
     

其它 s3 bucket 可选属性配置

solon.cloud.file.s3.file.buckets.demo1_bucket:
  pathStyleAccessEnabled: false #minio 一般要设为 true
  chunkedEncodingDisabled: false #一般要设为 true
  accelerateModeEnabled: false
  payloadSigningEnabled: false
  dualstackEnabled: false
  forceGlobalBucketAccessEnabled: false
  useArnRegionEnabled: false
  regionalUsEast1EndpointEnabled: false

4、应用示例

public class DemoApp {
    public void main(String[] args) {
        SolonApp app = Solon.start(DemoApp.class, args);

        String key = "test/" + Utils.guid();
        String val = "Hello world!";
        
        //上传媒体
        Result rst = CloudClient.file().put(key, new Media(val));
        
        //获取媒体,并转为字符串
        String val2 = CloudClient.file().get(key).bodyAsString();
    }
}

5、代码演示

https://gitee.com/noear/solon-examples/tree/main/9.Solon-Cloud/demo9042-file_aws_s3