feat: udpate upload content type

This commit is contained in:
yanghao05
2025-04-18 14:45:06 +08:00
parent 2854afec53
commit ac65302601
18 changed files with 228 additions and 23 deletions

View File

@@ -41,7 +41,7 @@ func Provide(opts ...opt.Option) error {
WithRegion(config.Region)
return &OSSClient{
client: oss.NewClient(cfg),
client: oss.NewClient(cfg.WithUseCName(true).WithEndpoint(*config.Host)),
internalClient: oss.NewClient(cfg.WithUseInternalEndpoint(true)),
config: &config,
}, nil

View File

@@ -3,6 +3,7 @@ package ali
import (
"context"
"strings"
"time"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
)
@@ -17,11 +18,11 @@ func (c *OSSClient) GetClient() *oss.Client {
return c.client
}
func (c *OSSClient) PreSignUpload(ctx context.Context, path string) (*oss.PresignResult, error) {
func (c *OSSClient) PreSignUpload(ctx context.Context, path, mimeType string) (*oss.PresignResult, error) {
request := &oss.PutObjectRequest{
Bucket: oss.Ptr(c.config.Bucket),
Key: oss.Ptr("quyun/" + strings.Trim(path, "/")),
ContentType: oss.Ptr("multipart/form-data"),
ContentType: oss.Ptr(mimeType),
}
return c.client.Presign(ctx, request)
}
@@ -38,3 +39,17 @@ func (c *OSSClient) Download(ctx context.Context, path, dest string) error {
}
return nil
}
// GetSignedUrl
func (c *OSSClient) GetSignedUrl(ctx context.Context, path string) (string, error) {
request := &oss.GetObjectRequest{
Bucket: oss.Ptr(c.config.Bucket),
Key: oss.Ptr(path),
}
preSign, err := c.client.Presign(ctx, request, oss.PresignExpires(time.Minute*5))
if err != nil {
return "", err
}
return preSign.URL, nil
}