使用aws go-sdk访问cloudflare R2文件

准备 需要准备Cloudflare的accountId,相应的R2 ak sk 和bucketName等信息. var ( accountId = "xxxxx" accessKeyId = "cbdade718b2ca877882csssssfcf" accessKeySecret = "04917c7d745422022e266f6b06" bucketName = "gopher" ) 完整代码 package main import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/s3" "log" ) func main() { var ( accountId = "xxxxx" accessKeyId = "cbdade718b2ca877882csssssfcf" accessKeySecret = "04917c7d745422022e266f6b06" bucketName = "gopher" ) var r2Resolver = aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { return aws.Endpoint{ URL: fmt.Sprintf("https://%s.r2.cloudflarestorage.com", accountId), }, nil }) cfg, err := config....