feat: support send ali code
This commit is contained in:
@@ -7,8 +7,29 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
|
||||
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
|
||||
)
|
||||
|
||||
func NewOSSClient(cfg *Config) (*OSSClient, error) {
|
||||
cred := credentials.NewStaticCredentialsProvider(cfg.AccessKeyId, cfg.AccessKeySecret)
|
||||
|
||||
conf := oss.LoadDefaultConfig().
|
||||
WithCredentialsProvider(cred).
|
||||
WithRegion(cfg.Region).
|
||||
WithUseCName(true).
|
||||
WithEndpoint(*cfg.Host)
|
||||
|
||||
cfgInternal := oss.LoadDefaultConfig().
|
||||
WithCredentialsProvider(cred).
|
||||
WithRegion(cfg.Region)
|
||||
|
||||
return &OSSClient{
|
||||
client: oss.NewClient(conf),
|
||||
internalClient: oss.NewClient(cfgInternal),
|
||||
config: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type OSSOption func(*OSSOptions)
|
||||
|
||||
type OSSOptions struct {
|
||||
@@ -42,7 +63,11 @@ func (c *OSSClient) GetClient() *oss.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
func (c *OSSClient) PreSignUpload(ctx context.Context, path, mimeType string, opts ...OSSOption) (*oss.PresignResult, error) {
|
||||
func (c *OSSClient) PreSignUpload(
|
||||
ctx context.Context,
|
||||
path, mimeType string,
|
||||
opts ...OSSOption,
|
||||
) (*oss.PresignResult, error) {
|
||||
request := &oss.PutObjectRequest{
|
||||
Bucket: oss.Ptr(c.config.Bucket),
|
||||
Key: oss.Ptr(c.GetSavePath(path)),
|
||||
|
||||
Reference in New Issue
Block a user