fix content type for video

This commit is contained in:
namhq1989 2023-01-12 16:08:17 +07:00
parent ce13b7762f
commit 0089757f02
2 changed files with 14 additions and 1 deletions

View File

@ -11,3 +11,9 @@ var Buckets = struct {
var listBuckets = []string{
Buckets.HelpCenter,
}
var ListTypes = struct {
Video string
}{
Video: "video",
}

View File

@ -4,10 +4,11 @@ import (
"context"
"fmt"
"net/url"
"strings"
"time"
)
func (c Client) GetPresignedURL(ctx context.Context, bucket, object string, expiry time.Duration) string {
func (c Client) GetPresignedURL(ctx context.Context, bucket, object, fileType string, expiry time.Duration) string {
// default 15 min
if expiry == 0 {
expiry = 15 * time.Minute
@ -17,6 +18,12 @@ func (c Client) GetPresignedURL(ctx context.Context, bucket, object string, expi
reqParams := make(url.Values)
reqParams.Set("response-content-disposition", fmt.Sprintf("attachment; filename=\"%s\"", object))
// add content type for video
if fileType == ListTypes.Video {
parts := strings.Split(object, ".")[1]
reqParams.Set("response-content-type", fmt.Sprintf("video/%s", parts[len(parts)-1]))
}
// get
presignedURL, err := c.client.PresignedGetObject(ctx, bucket, object, expiry, reqParams)
if err != nil {