fix: s3 browser preview (#580)

This commit is contained in:
withchao
2023-07-17 17:23:39 +08:00
committed by GitHub
parent cb59f05734
commit b95420ef8e
6 changed files with 39 additions and 35 deletions
+16 -10
View File
@@ -248,21 +248,27 @@ func (c *Cos) ListUploadedParts(ctx context.Context, uploadID string, name strin
}
func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
//reqParams := make(url.Values)
//if opt != nil {
// if opt.ContentType != "" {
// reqParams.Set("Content-Type", opt.ContentType)
// }
// if opt.ContentDisposition != "" {
// reqParams.Set("Content-Disposition", opt.ContentDisposition)
// }
//}
var option *cos.PresignedURLOptions
if opt != nil {
query := make(url.Values)
if opt.ContentType != "" {
query.Set("response-content-type", opt.ContentType)
}
if opt.Filename != "" {
query.Set("response-content-disposition", `attachment; filename="`+opt.Filename+`"`)
}
if len(query) > 0 {
option = &cos.PresignedURLOptions{
Query: &query,
}
}
}
if expire <= 0 {
expire = time.Hour * 24 * 365 * 99 // 99 years
} else if expire < time.Second {
expire = time.Second
}
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, nil)
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, option)
if err != nil {
return "", err
}