I'm trying to resize all of the pictures in my S3 bucket, but I am getting an error when I pass bucket into my resize_images function. For the sake of the this example, I've limited the pictures I pull to 5 (let's assume I need to maintain this structure).
This is the error I have have been getting:
./mass_resize.go:92: cannot use mybucket (type *s3.Bucket) as type s3.Bucket in function argument
This is the code:
package main
import (
"fmt"
"launchpad.net/goamz/aws"
"launchpad.net/goamz/s3"
"log"
"image"
"bytes"
"github.com/nfnt/resize"
"image/jpeg"
// "reflect"
)
func resize_images(image_keys []s3.Key, mybucket s3.Bucket) {
for _, v := range image_keys {
// check to see if this image is already in small version
image_data, err := mybucket.Get(v.Key)
if err != nil {
panic(err.Error())
} else {
fmt.Println("success")
}
image_bytes := []byte(image_data)
original_image, _, err := image.Decode(bytes.NewReader(image_bytes))
if err != nil {
fmt.Println("Error occurred after image.Decode function")
panic(err.Error())
} else {
fmt.Println("Another success")
}
new_image := resize.Resize(160, 0, original_image, resize.Lanczos3)
if new_image != nil {
fmt.Println("Image has been resized");
}
buf := new(bytes.Buffer)
err = jpeg.Encode(buf, new_image, nil)
if err != nil {
fmt.Println("Error occurred while encoding the new_image into a buffer")
fmt.Println(err)
}
send_S3 := buf.Bytes()
new_path := v.Key + "_sm"
PublicRead := s3.ACL("public-read")
err = mybucket.Put(new_path, send_S3, "image/jpg", PublicRead)
if err != nil {
fmt.Println("-----------------------------------------------")
fmt.Println("Error occurred in the mybucket.Put function")
fmt.Println(err)
fmt.Println(v.Key)
fmt.Println("-----------------------------------------------")
} else {
fmt.Println("Upload was successful")
}
}
}
func main() {
// connect to S3
auth := aws.Auth{
AccessKey: "key",
SecretKey: "secret",
}
useast := aws.USEast
connection := s3.New(auth, useast)
mybucket := connection.Bucket("bucket")
// pull the first 5 picture keys
res, err := mybucket.List("", "", "", 5)
if err != nil {
log.Fatal(err)
}
resize_images(res.Contents, mybucket)
}
Any ideas what this error means? Still learning Go, and I don't understand why I can't pass the s3 bucket into my function. An explanation would be very appreciated!