Search code examples
imagegoamazon-s3bufferminio

uploading image buffer with minio


I am attempting to upload an image.Image (image.NRGBA) to storage space with minio. Here is my code:

buff := new(bytes.Buffer)

err = png.Encode(buff, image)
if err != nil {
    fmt.Println("failed to create buffer", err)
}

reader := bytes.NewReader(buff.Bytes())

n, err := minioClient.FPutObject(bucketName, objectName, reader, minio.PutObjectOptions{ContentType:contentType})
if err != nil {
    log.Fatalln(err)
}

I get the error: cannot use reader (type *bytes.Reader) as type string in argument to minioClient.FPutObject


Solution

  • The minio package's FPut* functions take the name of a file, i.e., a string. Use the PutObject function (or its context variant) to pass in anything that implements io.Reader, such as your reader variable.