Giter VIP home page Giter VIP logo

Comments (1)

dicksonli avatar dicksonli commented on May 14, 2024 1

Currently, The ApiTable project was support following OSS type: AWS S3, Qiniu Cloud and MINIO. If you'd like to using one of them.
You just need to update starter.oss.type:xxx on application.xml. If you'd like support other, such at ALIYUN Oss. You can add some class
to compatible it. Following is demo how to support ALIYUN Oss.

Becuase the project ApiTable is using SpringCloud, so that let project support ALIYUN Oss not difficul, just need to add some class.

  1. Add Aliyun class on autoconfigure\OssProperties class. The new Aliyun class
    include some fields which is using to construct AliyunClient.

public static class Aliyun {

    private String endpoint;

    private String accessKeyId;

    private String accessKeySecret;

    private String bucketName;

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }
}
  1. Add get/set on OssProperties

    public void setQiniu(Qiniu qiniu) {
    this.qiniu = qiniu;
    }

    public Aliyun getAliyun() {
    return aliyun;
    }

  2. Add new ALIYUN enum on OssType
    public enum OssType {
    ...

     /**
      * Aliyun Oss
      */
     ALIYUN,
    
     MINIO
    

    }

  3. Add class AliyunAutoConfiguration on package com.apitable.starter.oss.autoconfigure which is use to input the property and contruct AliyunOssClientRequestFactory instance

@configuration(proxyBeanMethods = false)
@ConditionalOnClass(AliyunClient.class)
@ConditionalOnProperty(value = "starter.oss.type", havingValue = "aliyun")
public class AliyunAutoConfiguration extends OssConnectionConfiguration {

public AliyunAutoConfiguration(OssProperties properties) {
    super(properties);
}

@Bean
@ConditionalOnMissingBean(OssClientRequestFactory.class)
OssClientRequestFactory ossClientRequestFactory() {
    Aliyun aliyun = getProperties().getAliyun();
    return new AliyunOssClientRequestFactory(aliyun.getEndpoint(), aliyun.getAccessKey(), aliyun.getSecretKey(), aliyun.getBucketPolicy());
}

}

  1. Add class AliyunOssClientRequestFactory on package com.apitable.starter.oss.core.aliyun which is use to construct OssClientRequest.
    public class AliyunOssClientRequestFactory implements OssClientRequestFactory {

    private final String endpoint;

    private final String accessKey;

    private final String secretKey;

    private final String bucketPolicyJson;

    public AliyunOssClientRequestFactory(String endpoint, String accessKey, String secretKey, String bucketPolicyJson) {
    this.endpoint = endpoint;
    this.accessKey = accessKey;
    this.secretKey = secretKey;
    this.bucketPolicyJson = bucketPolicyJson;
    }

    @OverRide
    public OssClientRequest createClient() {
    OSS aliyunClient = new OSSClientBuilder().build(endpoint, accessKey, secretKey);
    return new AliyunOssClientRequest(aliyunClient, true, bucketPolicyJson);
    }
    }

  2. Add class AliyunOssClientRequest on package com.apitable.starter.oss.core.aliyun which is use to override some oss operate method for AbstractOssClientRequest. here is call aliyun sdk to operate oss.
    package com.apitable.starter.oss.core.aliyun;
    import com.aliyun.oss.OSS;
    import com.apitable.starter.oss.core.OssClientRequest;
    import com.apitable.starter.oss.core.OssClientRequestFactory;
    public class AliyunOssClientRequest extends AbstractOssClientRequest {
    public AliyunOssClientRequest(OSS aliyunClient) {
    ...
    }

    @OverRide
    protected boolean isBucketExist(String bucketName) {
    ...
    }

    @OverRide
    public UrlFetchResponse uploadRemoteUrl(String bucketName, String remoteSrcUrl, String keyPath) throws IOException {
    ...
    }

    @OverRide
    public void uploadStreamForObject(String bucketName, InputStream in, String keyPath) throws IOException {
    ...
    }

    @OverRide
    public void uploadStreamForObject(String bucketName, InputStream in, String path, String mimeType, String digest) throws IOException {
    ...
    }

    @OverRide
    public OssObject getObject(String bucketName, String path) {
    ...
    }

    @OverRide
    public OssStatObject getStatObject(String bucketName, String key) {
    ...
    }

    @OverRide
    public void executeStreamFunction(String bucketName, String key, Consumer function) {
    ...
    }

    @OverRide
    public boolean deleteObject(String bucketName, String key) {
    ...
    }

    @OverRide
    public void refreshCdn(String bucketName, String[] url) {
    throw new Error("minio is not implemented");
    }

    @OverRide
    public OssUploadAuth uploadToken(String bucket, String key, long expires, OssUploadPolicy uploadPolicy) {
    ...
    }

    @OverRide
    public boolean isValidCallback(String originAuthorization, String url, byte[] body, String contentType) {
    // TODO minio support immediately
    return false;
    }
    }

  3. Add config on application.yml
    starter:
    type: ${OSS_CLIENT_TYPE:aliyun}
    aliyun:
    endpoint: ${ALIYUN_ENDPOINT:http://aliyun:9001}
    access-key: ${ALIYUN_ACCESS_KEY:apitable}
    secret-key: ${ALIYUN_SECRET_KEY:apitable@com}
    bucket-policy: ${ALIYUN_BUCKET_POLICY:'...'}

  4. Add environment variable on .env file

ALIYUN

ALIYUN_ACCESS_KEY=apitable
ALIYUN_SECRET_KEY=apitable@com

APITable's default OSS storage is MinIO, uploading attachments follows the s3 protocol

So, assuming you want to access the OSS cloud storage of Azure or AWS, how do you modify the code?

you can choose a public cloud OSS and try to access it Expectation: After accessing, create a new "attachment column" on the APITable, and any attachment can be uploaded and stored normally.

from apitable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.