https
This commit is contained in:
parent
4489f801ca
commit
ccc7894e50
|
|
@ -114,7 +114,7 @@ func (s *Minio) List(objectPrefix string) ([]string, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Minio) Url(objectName string, expire time.Duration) string {
|
||||
func (s *Minio) Url(objectName string, expire time.Duration, https ...bool) string {
|
||||
if err := s.Init(); err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
|
|
@ -122,11 +122,19 @@ func (s *Minio) Url(objectName string, expire time.Duration) string {
|
|||
if expire > time.Hour*24*7 || expire == -1 {
|
||||
expire = time.Hour * 24 * 7
|
||||
}
|
||||
|
||||
baseUrl := s.config.BaseUrl
|
||||
if len(https) > 1 && https[0] {
|
||||
if strings.HasPrefix(baseUrl, "http://") {
|
||||
baseUrl = "https://" + strings.TrimPrefix(baseUrl, "http://")
|
||||
}
|
||||
}
|
||||
|
||||
var params url.Values
|
||||
u, err := s.client.PresignedGetObject(s.config.Bucket, objectName, expire, params)
|
||||
if err != nil {
|
||||
log.Errorf("error:%s", err.Error())
|
||||
return fmt.Sprintf("%s/%s/%s", s.config.BaseUrl, s.config.Bucket, objectName)
|
||||
return fmt.Sprintf("%s/%s/%s", baseUrl, s.config.Bucket, objectName)
|
||||
}
|
||||
|
||||
return u.String()
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ func (s *Qiniu) Get(objectName, fileName string) error {
|
|||
return Download(url, fileName)
|
||||
}
|
||||
|
||||
func (s *Qiniu) Url(objectName string, expire time.Duration) string {
|
||||
func (s *Qiniu) Url(objectName string, expire time.Duration, https ...bool) string {
|
||||
mac := qbox.NewMac(s.config.AK, s.config.SK)
|
||||
cfg := storage.Config{
|
||||
UseHTTPS: false,
|
||||
|
|
@ -169,8 +169,10 @@ func (s *Qiniu) Url(objectName string, expire time.Duration) string {
|
|||
if len(domains) <= 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
domain := "https://" + domains[0].Domain
|
||||
domain := "http://" + domains[0].Domain
|
||||
if len(https) > 0 && https[0] {
|
||||
domain = "https://" + domains[0].Domain
|
||||
}
|
||||
|
||||
if expire == 0 {
|
||||
return storage.MakePublicURLv2(domain, objectName)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ type Storage interface {
|
|||
Put(fileName, objectName string, onProcess func(fsize, uploaded int64)) error
|
||||
Get(objectName, fileName string) error
|
||||
Del(objectName string) error
|
||||
Url(objectName string, expire time.Duration) string
|
||||
Url(objectName string, expire time.Duration, https ...bool) string //https参数是否生成https参数
|
||||
Stat(objectName string) (*ObjectInfo, error)
|
||||
List(objectPrefix string) ([]string, error)
|
||||
Fetch(url, objectName string, local ...bool) error //local参数决定是否先下载到本地在上传,七牛云下载企业微信的文件需要不能直接下载
|
||||
|
|
|
|||
Loading…
Reference in New Issue