Closed MohitKS5 closed 4 years ago
The simplest option is to use the Encode
function (imaging.Encode
or jpeg.Encode
or png.Encode
etc) to write the image to a bytes.Buffer
, then pass the buffer to s3
(it implements the io.Reader
interface).
A better but a little bit trickier option is to use the io.Pipe
function that returns both an io.Writer
and an io.Reader
. Then you need to start a goroutine, encoding the image to the writer and pass the reader to s3
.
Documentation: https://golang.org/pkg/io/#Pipe
Example: https://github.com/disintegration/bebop/blob/97a8b9d7e78c883d79924976850e1011892c3fe7/avatar/service.go#L235
Thanks !
After resizing I want to upload it to s3 which takes io.Reader as input. One obvious choice is saving it to a file and then read it. Is there any other way ?