s3 public read

pull/1080/head
withchao 2 years ago
parent 77289e68b4
commit a71b143b1c

@ -288,7 +288,7 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
style = append(style, "format/"+opt.Image.Format) style = append(style, "format/"+opt.Image.Format)
} }
if len(style) > 0 { if len(style) > 0 {
imageMogr = "&imageMogr2/thumbnail/" + strings.Join(style, "/") + "/ignore-error/1" imageMogr = "imageMogr2/thumbnail/" + strings.Join(style, "/") + "/ignore-error/1"
} }
} }
if opt.ContentType != "" { if opt.ContentType != "" {
@ -310,11 +310,14 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
if err != nil { if err != nil {
return "", err return "", err
} }
urlStr := rawURL.String()
if imageMogr != "" { if imageMogr != "" {
urlStr += imageMogr if rawURL.RawQuery == "" {
rawURL.RawQuery = imageMogr
} else {
rawURL.RawQuery = rawURL.RawQuery + "&" + imageMogr
}
} }
return urlStr, nil return rawURL.String(), nil
} }
func (c *Cos) getPresignedURL(ctx context.Context, name string, expire time.Duration, opt *cos.PresignedURLOptions) (*url.URL, error) { func (c *Cos) getPresignedURL(ctx context.Context, name string, expire time.Duration, opt *cos.PresignedURLOptions) (*url.URL, error) {
@ -322,16 +325,16 @@ func (c *Cos) getPresignedURL(ctx context.Context, name string, expire time.Dura
return c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, opt) return c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, opt)
} }
u := c.client.Object.GetObjectURL(name) u := c.client.Object.GetObjectURL(name)
if opt.Query != nil && len(*opt.Query) > 0 { //if opt.Query != nil && len(*opt.Query) > 0 {
query := u.Query() // query := u.Query()
if len(query) == 0 { // if len(query) == 0 {
query = *opt.Query // query = *opt.Query
} else { // } else {
for key := range *opt.Query { // for key := range *opt.Query {
query[key] = (*opt.Query)[key] // query[key] = (*opt.Query)[key]
} // }
} // }
u.RawQuery = query.Encode() // u.RawQuery = query.Encode()
} //}
return u, nil return u, nil
} }

Loading…
Cancel
Save