minio/presigned_url.go

31 lines
698 B
Go
Raw Permalink Normal View History

2023-01-06 04:56:26 +00:00
package minio
import (
"context"
"fmt"
2023-01-08 13:39:17 +00:00
"net/url"
2023-01-06 04:56:26 +00:00
"time"
)
func (c Client) GetPresignedURL(ctx context.Context, bucket, object string, expiry time.Duration) string {
// default 15 min
if expiry == 0 {
expiry = 15 * time.Minute
}
// params
2023-01-08 13:39:17 +00:00
reqParams := make(url.Values)
reqParams.Set("response-content-disposition", fmt.Sprintf("attachment; filename=\"%s\"", object))
2023-01-06 04:56:26 +00:00
// get
2023-01-08 13:39:17 +00:00
presignedURL, err := c.client.PresignedGetObject(ctx, bucket, object, expiry, reqParams)
2023-01-06 04:56:26 +00:00
if err != nil {
2023-01-08 13:39:17 +00:00
fmt.Printf("[minio.GetPresignedURL][%s] get object '%s' error: %s \n", bucket, object, err.Error())
fmt.Printf("params %v \n", reqParams)
2023-01-06 04:56:26 +00:00
return ""
}
// return
return presignedURL.String()
}