Skip to content

Commit 8dc46c4

Browse files
erhuzcloudlena
authored andcommitted
Detect MIME type on upload instead of hardcoding application/octet-stream
1 parent 6b1114b commit 8dc46c4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/app/s3manager/create_object.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package s3manager
33
import (
44
"fmt"
55
"log"
6+
"mime"
67
"net/http"
8+
"path/filepath"
79

810
"github.com/gorilla/mux"
911
"github.com/minio/minio-go/v7"
@@ -32,7 +34,14 @@ func HandleCreateObject(s3 S3, sseInfo SSEType) http.HandlerFunc {
3234
}
3335
}()
3436

35-
opts := minio.PutObjectOptions{ContentType: "application/octet-stream"}
37+
contentType := fileHeader.Header.Get("Content-Type")
38+
if contentType == "" || contentType == "application/octet-stream" {
39+
contentType = mime.TypeByExtension(filepath.Ext(fileHeader.Filename))
40+
}
41+
if contentType == "" {
42+
contentType = "application/octet-stream"
43+
}
44+
opts := minio.PutObjectOptions{ContentType: contentType}
3645

3746
if sseInfo.Type == "KMS" {
3847
opts.ServerSideEncryption, err = encrypt.NewSSEKMS(sseInfo.Key, nil)

0 commit comments

Comments
 (0)