aboutsummaryrefslogtreecommitdiff
path: root/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/util.go')
-rw-r--r--util/util.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go
index 381db94..ade5eae 100644
--- a/util/util.go
+++ b/util/util.go
@@ -4,6 +4,8 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
+ "mime/multipart"
+ "net/http"
"os"
"regexp"
"strings"
@@ -225,3 +227,27 @@ func CreateUniqueID(actor string) (string, error) {
return newID, nil
}
+
+func GetFileContentType(out multipart.File) (string, error) {
+ buffer := make([]byte, 512)
+
+ _, err := out.Read(buffer)
+ if err != nil {
+ return "", err
+ }
+
+ out.Seek(0, 0)
+
+ contentType := http.DetectContentType(buffer)
+
+ return contentType, nil
+}
+
+func GetContentType(location string) string {
+ elements := strings.Split(location, ";")
+ if len(elements) > 0 {
+ return elements[0]
+ } else {
+ return location
+ }
+}