mirror of
https://github.com/usememos/memos.git
synced 2025-01-28 08:05:03 +08:00
fix: failed to upload OSS with S3 SDK (#1792)
Fix failed to upload OSS with S3 SDK Co-authored-by: Athurg Feng <athurg@gooth.org>
This commit is contained in:
parent
11a385cda6
commit
c27c6cea13
1 changed files with 11 additions and 5 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
s3config "github.com/aws/aws-sdk-go-v2/config"
|
s3config "github.com/aws/aws-sdk-go-v2/config"
|
||||||
|
@ -29,13 +30,18 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(ctx context.Context, config *Config) (*Client, error) {
|
func NewClient(ctx context.Context, config *Config) (*Client, error) {
|
||||||
|
// For some s3-compatible object stores, converting the hostname is not required,
|
||||||
|
// and not setting this option will result in not being able to access the corresponding object store address.
|
||||||
|
// But Aliyun OSS should disable this option
|
||||||
|
hostnameImmutable := true
|
||||||
|
if strings.HasSuffix(config.EndPoint, "aliyuncs.com") {
|
||||||
|
hostnameImmutable = false
|
||||||
|
}
|
||||||
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
|
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||||
return aws.Endpoint{
|
return aws.Endpoint{
|
||||||
URL: config.EndPoint,
|
URL: config.EndPoint,
|
||||||
SigningRegion: config.Region,
|
SigningRegion: config.Region,
|
||||||
// For some s3-compatible object stores, converting the hostname is not required,
|
HostnameImmutable: hostnameImmutable,
|
||||||
// and not setting this option will result in not being able to access the corresponding object store address.
|
|
||||||
HostnameImmutable: true,
|
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue