I'm trying to download a few files from my website and upload them to amazons3.
Here is my code:
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)
}
I keep getting a run time error of a nil pointer dereference the error doesn't help much but for some reason I think it might have to do with ssl but here is the entire error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x236ffe]
goroutine 1 [running]:
panic(0x4743c0, 0xc82000a0e0)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
github.com/aws/aws-sdk-go/service/s3.validateSSERequiresSSL(0xc820066380)
/Users/name/work/src/github.com/aws/aws-sdk-go/service/s3/sse.go:15 +0x17e
github.com/aws/aws-sdk-go/aws/request.(*HandlerList).Run(0xc820066478, 0xc820066380)
/Users/name/work/src/github.com/aws/aws-sdk-go/aws/request/handlers.go:136 +0xc3
github.com/aws/aws-sdk-go/aws/request.(*Request).Build(0xc820066380, 0x0, 0x0)
/Users/name/work/src/github.com/aws/aws-sdk-go/aws/request/request.go:189 +0x69
github.com/aws/aws-sdk-go/aws/request.(*Request).Sign(0xc820066380, 0x0, 0x0)
/Users/name/work/src/github.com/aws/aws-sdk-go/aws/request/request.go:210 +0x31
github.com/aws/aws-sdk-go/aws/request.(*Request).Send(0xc820066380, 0x0, 0x0)
/Users/name/work/src/github.com/aws/aws-sdk-go/aws/request/request.go:261 +0x6f4
github.com/aws/aws-sdk-go/service/s3/s3manager.(*uploader).singlePart(0xc8201520f0, 0x8bb980, 0xc82014a030, 0xc82000a140, 0x0, 0x0)
/Users/name/work/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go:449 +0x1fc
github.com/aws/aws-sdk-go/service/s3/s3manager.(*uploader).upload(0xc8201520f0, 0xc8201520f0, 0x0, 0x0)
/Users/name/work/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go:355 +0x563
github.com/aws/aws-sdk-go/service/s3/s3manager.Uploader.Upload(0x500000, 0x5, 0x0, 0x2710, 0xe00240, 0xc820156018, 0xc82016e000, 0x0, 0x0, 0x0, ...)
/Users/name/work/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go:329 +0x15a
main.main()
/Users/name/work/src/gitlab.com/user/project/test/main.go:39 +0x59f
exit status 2