minio/presigned_url.go

37 lines
917 B
Go
Raw Normal View History

2023-01-06 04:56:26 +00:00
package minio
import (
"context"
"fmt"
"time"
)
2023-01-12 09:08:17 +00:00
func (c Client) GetPresignedURL(ctx context.Context, bucket, object, fileType string, expiry time.Duration) string {
2023-01-06 04:56:26 +00:00
// default 15 min
if expiry == 0 {
expiry = 15 * time.Minute
}
// params
2023-01-12 09:49:05 +00:00
//reqParams := make(url.Values)
//
//// add content type for video
//if fileType == ListTypes.Video {
// parts := strings.Split(object, ".")
// reqParams.Set("response-content-type", fmt.Sprintf("video/%s", parts[len(parts)-1]))
//} else {
// reqParams.Set("response-content-disposition", fmt.Sprintf("attachment; filename=\"%s\"", object))
//}
2023-01-12 09:08:17 +00:00
2023-01-06 04:56:26 +00:00
// get
2023-01-12 09:49:05 +00:00
presignedURL, err := c.client.PresignedGetObject(ctx, bucket, object, expiry, nil)
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())
2023-01-12 09:49:05 +00:00
//fmt.Printf("params %v \n", reqParams)
2023-01-06 04:56:26 +00:00
return ""
}
// return
return presignedURL.String()
}