我正在尝试使用以下代码连接到 IBM Cloud 对象存储(Cleversafe),但出现以下错误
“错误响应:MissingRegion:找不到区域配置”
package main
import (
"fmt"
"os"
"bytes"
"net/http"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/aws/session"
)
func main() {
fmt.Printf("Starting ...")
aws_access_key_id := "some id"
aws_secret_access_key := "some key"
token := ""
creds := credentials.NewStaticCredentials(aws_access_key_id, aws_secret_access_key, token)
fmt.Printf("creds: ", creds)
_, err := creds.Get()
if err != nil {
fmt.Printf("bad credentials: %s", err)
}
//EndpointResolver endpoints.Resolver
cfg := aws.NewConfig().WithEndpoint("dal.ibmselect.objstor.com").WithCredentials(creds)
fmt.Printf("cfg: %+v \n", cfg)
//cfg := aws.NewConfig().WithEndpointResolver()
//cfg := aws.NewConfig().WithCredentials(creds)
svc := s3.New(session.New(), cfg)
fmt.Printf("svc: %+v \n", svc)
file, err := os.Open("./test.jpg")
if err != nil {
fmt.Printf("err opening file: %s", err)
}
defer file.Close()
fileInfo, _ := file.Stat()
size := fileInfo.Size()
buffer := make([]byte, size) // read file content to buffer
file.Read(buffer)
fileBytes := bytes.NewReader(buffer)
fileType := http.DetectContentType(buffer)
path := file.Name()
params := &s3.PutObjectInput{
Bucket: aws.String("cosv1-jlnab"),
Key: aws.String(path),
Body: fileBytes,
ContentLength: aws.Int64(size),
ContentType: aws.String(fileType),
}
resp, err := svc.PutObject(params)
if err != nil {
fmt.Printf("bad response: %s \n", err)
}
fmt.Printf("response %s", awsutil.StringValue(resp))
}