我正在尝试从我的网站下载一些文件并将它们上传到 amazons3。
这是我的代码:
import (
"log"
"net/http"
"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/s3manager"
)
func main() {
// Make a GET request to an image to be downloaded and uploaded to s3
resp, err := http.Get("http://my-site.com/image.jpg")
if err != nil {
log.Fatal(err)
}
// Get the AWS credentials
creds := credentials.NewSharedCredentials("/Users/name/.aws/credentials", "default")
// Set up config
config := &aws.Config{
Region: aws.String("US Standard"),
Credentials: creds,
}
// Set up a new AWS session
sess := session.New(config)
// Set up a new s3manager client
uploader := s3manager.NewUploader(sess)
result, err := uploader.Upload(&s3manager.UploadInput{
Body: resp.Body,
Bucket: aws.String("mimi-movies"),
Key: aws.String("mimi.jpg"),
})
if err != nil {
log.Fatalln("Failed to upload", err)
}
log.Println("Successfully uploaded to", result.Location)
}
我不断收到 nil 指针取消引用的运行时错误,该错误没有多大帮助,但出于某种原因,我认为这可能与 ssl 有关
阿波罗的战车
江户川乱折腾
一只萌萌小番薯
相关分类