30 lines
634 B
Go
30 lines
634 B
Go
|
package minio
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"net/url"
|
||
|
"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
|
||
|
reqParams := make(url.Values)
|
||
|
reqParams.Set("response-content-disposition", fmt.Sprintf("attachment; filename=\"%s\"", object))
|
||
|
|
||
|
// get
|
||
|
presignedURL, err := c.client.PresignedGetObject(context.Background(), bucket, object, expiry, reqParams)
|
||
|
if err != nil {
|
||
|
fmt.Println("[minio.GetPresignedURL] error:", err.Error())
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
// return
|
||
|
return presignedURL.String()
|
||
|
}
|