09e1642335
Fixes #995. Added mime type detection in SaveBytes for MinIO, OSS, S3, and TOS to prevent images from being incorrectly saved as text/csv.
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package utils
|
|
|
|
import "strings"
|
|
|
|
// GetContentTypeByExt returns the content type based on file extension
|
|
func GetContentTypeByExt(ext string) string {
|
|
switch strings.ToLower(ext) {
|
|
case ".csv":
|
|
return "text/csv; charset=utf-8"
|
|
case ".json":
|
|
return "application/json"
|
|
case ".pdf":
|
|
return "application/pdf"
|
|
case ".doc":
|
|
return "application/msword"
|
|
case ".docx":
|
|
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
case ".xls":
|
|
return "application/vnd.ms-excel"
|
|
case ".xlsx":
|
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
case ".png":
|
|
return "image/png"
|
|
case ".jpg", ".jpeg":
|
|
return "image/jpeg"
|
|
case ".gif":
|
|
return "image/gif"
|
|
case ".webp":
|
|
return "image/webp"
|
|
case ".svg":
|
|
return "image/svg+xml"
|
|
case ".txt":
|
|
return "text/plain; charset=utf-8"
|
|
case ".html", ".htm":
|
|
return "text/html; charset=utf-8"
|
|
case ".mp4":
|
|
return "video/mp4"
|
|
case ".mp3":
|
|
return "audio/mpeg"
|
|
case ".wav":
|
|
return "audio/wav"
|
|
case ".zip":
|
|
return "application/zip"
|
|
case ".tar":
|
|
return "application/x-tar"
|
|
case ".gz":
|
|
return "application/gzip"
|
|
case ".md":
|
|
return "text/markdown; charset=utf-8"
|
|
default:
|
|
return "application/octet-stream"
|
|
}
|
|
}
|