下面是使用aws s3的go-sdk上传文件,但是上传后的文件大小与实际文件大小不一致,下面是我写的代码:
package main
import (
"fmt"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
// aws s3 putObject example: aws s3api put-object --bucket db-backup-huawen --key truco/rpmlist.txt(上传到bucket的位置) --body ./rpmlist.txt(本地文件)
func main() {
sess, err := session.NewSession(&aws.Config{
MaxRetries: aws.Int(3),
Credentials: credentials.NewSharedCredentials("C:/Users/Administrator/Desktop/aws.ini", "aws-huawen-root"),
Region: aws.String("sa-east-1"),
})
if err != nil {
return
}
s3api := s3.New(sess)
input := &s3.PutObjectInput{
Body: aws.ReadSeekCloser(strings.NewReader("C:/Users/Administrator/Desktop/baxi_MGCenter_FULL_20230211_000001.bak")),
Bucket: aws.String("db-backup-huawen"),
Key: aws.String("truco/baxi_MGCenter_FULL_20230211_000001.bak"),
}
res, err := s3api.PutObject(input)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(res)
}
我已经严格按照文档调用了API,在程序执行过程中没有发现错误提示,我不明白是哪里出错了,下面是执行程序的输出:
以上是我上传到s3的文件,但文件大小与实际大小不一致:
1条答案
按热度按时间f0ofjuux1#
我发现了问题所在: