Comments (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.
- 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;
}
}
-
Add get/set on OssProperties
public void setQiniu(Qiniu qiniu) {
this.qiniu = qiniu;
}public Aliyun getAliyun() {
return aliyun;
} -
Add new ALIYUN enum on OssType
public enum OssType {
.../** * Aliyun Oss */ ALIYUN, MINIO
}
-
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());
}
}
-
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);
}
} -
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;
}
} -
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:'...'} -
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)
- 无法新增表格、表格数据,历史数据能修改。 HOT 2
- /nest/v1/datasheets/dstSNGWWT6eJuWLpJD/dataPack接口返回500
- fix:无法本地进行make bulid-docker HOT 1
- 大佬们,如何更新本地部署的apitable HOT 1
- 删除自动化时,提示删除成功但没有真实删除
- 自动化功能无法正常使用 HOT 1
- 更新最新版的apitable docker镜像后无法提交神奇表单 HOT 11
- 开发使用安装文档可以再详细一些。尤其是对于初次接触的用户
- Docker compose upgrade fail HOT 2
- Support Month/Day/Year to date formats
- 关于在文档中增加FAQ的建议
- Does deploying the all-in-one image demo require using sudo? HOT 4
- Recommend upgrading to CodeRabbit Pro
- fix: Need to change the banner of the webpage HOT 1
- question: Exporting xlsx/csv programmatically?
- docs: More
- 期望developer文档中能有更多的F&Q
- question: What is the purpose of init-appdata HOT 1
- question: A question about room-server client address HOT 1
- feat: It would be better to have postman collection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apitable.