gavin1
gavin1

Reputation: 13

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

Upvotes: 1

Views: 3504

Answers (2)

Hongbo Miao
Hongbo Miao

Reputation: 49884

You can use PutObject.

info, err := minioClient.PutObject(ctx, bucketName, objectName, reader, int64(len(bytes))), minio.PutObjectOptions{ContentType: contentType})

API doc is at https://docs.min.io/docs/golang-client-api-reference#PutObject

Upvotes: 0

torek
torek

Reputation: 489093

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.

Upvotes: 2

Related Questions