diff --git a/s3/s3.go b/s3/s3.go index bc550c35b8e8a66c19f47e5952869f37dcca5102..631ba97325a5f2af7d6bd6fcd77a19105060884b 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -5,9 +5,9 @@ import ( "context" "encoding/binary" "fmt" + "net/http" "net/url" "os" - "path" "strings" "time" @@ -142,7 +142,7 @@ func (s ClientWithHelpers) Upload(data []byte, bucket, fileName string, metadata return nil, ErrorS3ClientNotEstablished } - mimeType := getTypeForFilename(fileName) + mimeType := http.DetectContentType(data) putInput := &s3.PutObjectInput{ Bucket: aws.String(bucket), Key: aws.String(fileName), @@ -168,7 +168,7 @@ func (s ClientWithHelpers) UploadWithSettings(data []byte, bucket, fileName stri } if settings.MimeType == "" { - settings.MimeType = getTypeForFilename(fileName) + settings.MimeType = MIMEType(http.DetectContentType(data)) } putInput := &s3.PutObjectInput{ @@ -242,7 +242,7 @@ func (s ClientWithHelpers) UploadWithSettingsRevised(data []byte, bucket string, } if settings.MimeType == "" { - settings.MimeType = getTypeForFilename(fullFileName) + settings.MimeType = MIMEType(http.DetectContentType(data)) } putInput := &s3.PutObjectInput{ @@ -302,7 +302,7 @@ func (s ClientWithHelpers) UploadWith1DayExpiry(data []byte, bucket, fileName st } if mimeType == "" { - mimeType = getTypeForFilename(fileName) + mimeType = MIMEType(http.DetectContentType(data)) } expiry := 24 * time.Hour @@ -427,23 +427,6 @@ func (s ClientWithHelpers) UploadWithFileExtension(data []byte, bucket, filePref return response, nil } -func getTypeForFilename(f string) MIMEType { - ext := strings.ToLower(path.Ext(f)) - - switch ext { - case "pdf": - return MIMETypePDF - case "csv": - return MIMETypeCSV - case "zip": - return MIMETypeZIP - case "txt": - return MIMETypeText - } - - return MIMETypeDefault -} - func (s ClientWithHelpers) GetObject(bucket string, fileName string, isDebug bool) (*s3.GetObjectOutput, error) { if s.S3Client == nil { return nil, ErrorS3ClientNotEstablished