尝试使用 Go (lang) 中的 goamz/s3 包将文件字节上传到 S3 AWS。
我的代码是:
var (
awsAuth aws.Auth
region aws.Region
connection s3.S3
bucket *s3.Bucket
)
func init() {
// Set up the AWS S3 Connection config.
awsAuth = aws.Auth{
AccessKey: os.Getenv("ACCESS_KEY"), // change this to yours
SecretKey: os.Getenv("SECRET_KEY"),
}
fmt.Println("AWS: ", awsAuth)
region := aws.EUWest
connection := s3.New(awsAuth, region)
bucket = connection.Bucket(os.Getenv("S3_BUCKET")) // change this your bucket name
}
func uploadToS3(filename string, byteArray *[]byte) error {
var err error
//should check if file already uploaded, encrypted by this password
fmt.Printf("[uploadToS3] starting upload of %s\n", filename)
err = bucket.Put(filename, *byteArray, "text/plain; charset=utf-8", s3.PublicRead)
if err != nil {
fmt.Printf("[uploadToS3] error uploading: %s\n", err)
return err
} else {
fmt.Printf("[uploadToS3] done uploading %s\n", filename)
return nil
}
return nil // redundancy
}
我得到错误
[uploadToS3] error uploading: Put /filename: unsupported protocol scheme ""
从这里阅读:创建 ec2 安全组时不受支持的协议方案它认为这是因为该区域不正确,但是正如您所看到的,我在 init() 函数中设置它,所以我不知道它可能是什么
任何想法都非常感谢