minio/presigned_url.go

35 lines
775 B
Go

package minio
import (
"context"
"fmt"
"net/url"
"time"
)
func (c Client) GetPresignedURL(ctx context.Context, bucket, object, fileType string, expiry time.Duration) string {
// default 15 min
if expiry == 0 {
expiry = 15 * time.Minute
}
// params
reqParams := make(url.Values)
// set name for type "file"
if fileType == ListTypes.File {
reqParams.Set("response-content-disposition", fmt.Sprintf("attachment; filename=\"%s\"", object))
}
// get
presignedURL, err := c.client.PresignedGetObject(ctx, bucket, object, expiry, reqParams)
if err != nil {
fmt.Printf("[minio.GetPresignedURL][%s] get object '%s' error: %s \n", bucket, object, err.Error())
fmt.Printf("params %v \n", reqParams)
return ""
}
// return
return presignedURL.String()
}