feat: udpate upload content type
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user