Having trouble converting an image.Image to []byte. The problem spot is wrapped in dotted lines.
image_data, err := mybucket.Get(key)
if err != nil {
panic
You want a bytes.Buffer, not a bufio.Writer. bytes.Buffer is used when you need a writer that writes to memory. bufio.Writer just caches data in memory before forwarding it to another writer.
buf := new(bytes.Buffer)
err := jpeg.Encode(buf, new_image, nil)
send_s3 := buf.Bytes()
Adding on to Stephen's code, if you're using the aws s3 go SDK to put an object, your code would look like:
// create buffer
buff := new(bytes.Buffer)
// encode image to buffer
err = png.Encode(buff, new_image)
if err != nil {
fmt.Println("failed to create buffer", err)
}
// convert buffer to reader
reader := bytes.NewReader(buf.Bytes())
// use it in `PutObjectInput`
putInput := s3.PutObjectInput{
Bucket: aws.String("my_bucket"),
Body: reader,
}
// send response
resp, err := svc.PutObject(&putInput)